'Conda doesn't work in Vertex AI deeplearning images

When provisioning a VM on GCS with a single T4 GPU and Tensorflow conda doesn't work correctly. I can't create new virtual environments or install any packages.

$ conda info


active environment : base
active env location : /opt/conda
shell level : 1
user config file : /home/plateu/.condarc
populated config files : /opt/conda/.condarc
conda version : 4.11.0
conda-build version : not installed
python version : 3.7.12.final.0
virtual packages : __cuda=11.2=0
                  __linux=4.19.0=0
                  __glibc=2.28=0
                  __unix=0=0
                  __archspec=1=x86_64
base environment : /opt/conda  (writable)
conda av data dir : /opt/conda/etc/conda
conda av metadata url : None
channel URLs : https://conda.anaconda.org/conda-forge/linux-64
               https://conda.anaconda.org/conda-forge/noarch
               https://repo.anaconda.com/pkgs/main/linux-64
               https://repo.anaconda.com/pkgs/main/noarch
               https://repo.anaconda.com/pkgs/r/linux-64
               https://repo.anaconda.com/pkgs/r/noarch
package cache : /opt/conda/pkgs
               /home/plateu/.conda/pkgs
envs directories : /opt/conda/envs
               /home/plateu/.conda/envs
platform : linux-64
user-agent : conda/4.11.0 requests/2.26.0 CPython/3.7.12 Linux/4.19.0-18-cloud-amd64 debian/10 glibc/2.28
UID:GID : 1002:1003
netrc file : None
offline mode : False

Trying out the conda installation

$ conda create --name fm37 python=3.7.12

Collecting package metadata (current_repodata.json): failed

NotWritableError: The current user does not have write permissions to a required path.
   path: /opt/conda/pkgs/cache/18414ddb.json
   uid: 1002
   gid: 1003

 If you feel that permissions on this path are set incorrectly, you can manually
 change them by executing

 $ sudo chown 1002:1003 /opt/conda/pkgs/cache/18414ddb.json

 In general, it's not advisable to use 'sudo conda'.

Following the advise from conda:

$ sudo chown 1002:1003 /opt/conda/pkgs/cache/18414ddb.json

chown: cannot access '/opt/conda/pkgs/cache/18414ddb.json': No such file or directory

I really need to be able to create virtual envs in this VM as I SSH into it using VSCode and can't access any ipykernels from vscode unless they are in a conda env.

$ sudo /opt/conda/bin/conda create --name fm37 python=3.7.12

Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /opt/conda/envs/fm37

  added / updated specs:
     - python=3.7.12
   
  ..... etc.

So that works but only rudimentary. I get major problems using VSCode and I need to reinstall Tensorflow which was in the base environment, so should also be in any other environment.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source