14

I have a RHEL server with Anaconda3 installed. Each user in the system gets 2 GiG space in the /home/ folder and another large folder in a mounted drive. When the user is trying to create a conda environment using conda create -n my_env it fills all the .tar files in .conda folder and installation breaks. Is there a way I specify a custom location for the .conda folder.

Best Jagan

Jaganadh Gopinadhan
  • 460
  • 1
  • 7
  • 19

3 Answers3

10

you can use --prefix option documentation

Option 1: If you want to create your virtual environment in current directory then use

conda create --prefix=envName python=X.X

Option 2: if you want to mention the directory then give full path

conda create --prefix=/YourPath/yourEnvName python=x.x

Option 3: If you dont want to explicitly mention the path everytime and want all your environments to be stored somewhere else by default, you can set that up in your .condarc file documentation

You can do this in command line using:

conda config --add envs_dirs <path to directory>

envs_dirs in your .condarc file will add an additional location to the package cache search path.

Ajay Bisht
  • 585
  • 6
  • 8
  • 2
    The `--prefix` will help me in specifying the folder where the new environment will be created. The current issue is when the environment creation in progress it downloads packages and store it in `/home/userw123/.conda/pkgs` . This is the part which creates trouble. – Jaganadh Gopinadhan Aug 21 '18 at 23:21
  • 1
    In that case, when you mention the directory in your `.condarc` file , it will add an additional location to the package cache search path. Also try making `/home/userw123/.conda/pkgs` directory read-only so that access is denied if conda uses it as first directory to access. – Ajay Bisht Aug 21 '18 at 23:27
  • @Jaganadh did this answer work for your original problem? – Ajay Bisht Aug 22 '18 at 12:28
  • 2
    @AjayBisht How to move existing envs to other folder? Can we just simply `mv` all the folders in `~/.conda/envs/` to the desired folder? – Jon Sep 15 '18 at 05:14
  • @Jon to move follow this link. I suggest just uninstall and start over: https://docs.anaconda.com/anaconda/user-guide/tasks/move-directory/ – Robert Lugg Sep 27 '19 at 18:41
  • How to list all conda env under the current working directory? I mean: `conda env list` will not list envs created with `--prefix=relativePath` in your answer. – NeoZoom.lua Apr 01 '23 at 14:32
6

Came across this while having a similar problem with lack of space in my home directory...

Building on Ajay Bisht's solution, to change the package cache search path, you can set

conda config --add pkgs_dirs <path to directory>/pkgs

as well as

conda config --add envs_dirs <path to directory>/envs

See here https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#specify-package-directories-pkgs-dirs

john
  • 177
  • 1
  • 8
4

I had the same disk space problem. All docs and forums told me to uninstall and reinstall anaconda to new location... I didn't want that, so here another approach:

  • copy anaconda folder to new location. lets assume old location /home/uname/anaconda3, new location /home/uname/mountx/anaconda3 cp -r /home/uname/anaconda3 /home/uname/mountx/anaconda3
  • rename original anaconda folder (to be sure its not used later) mv /home/uname/anaconda3 /home/uname/anaconda3.bak
  • replace all occurrences of "/home/uname/anaconda3" with "/home/uname/mountx/anaconda3". do this in new anaconda folder, .conda, .bashrc, and your projects. I used PyCharm with no open project to do the replacing, sed in a shell might also work
  • start new anaconda shell and PyCharm to test it
  • remove renamed original anaconda folder afterwards if it works rm -rf /home/uname/anaconda3.bak
  • done

worked fine like a PyCharm for me :)