Search code examples
pythonrefreshupdatescondavirtual-environment

Refresh or detect conda environments


I am working in a business environment with different disks, of which on of them is my personal space (e.g. H:\). I created a new conda environment on that disk, and it was listed in the conda info --envs. Today I rebooted my machine and the conda directory is still there, but it is not anymore in the conda info --envs because that information is stored on a disk that gets wiped every time I log out.

I can still activate the environment by using activate H:\path\to\env, but not with its name. Is there a way to 'update' my conda list of environments, looking at a specific folder?


Solution

  • You can add a directory containing environments using the command:

    conda config --add envs_dirs /path/to/directory/containing/environments
    

    On Linux:

    (root) [root@af511ebe9357 /]# ls /condaenvs/
    devops  machine_learning  so  statistics  throwaway
    (root) [root@af511ebe9357 /]# conda info --envs
    # conda environments:
    #
    root                  *  /conda
    
    (root) [root@af511ebe9357 /]# conda config --add envs_dirs /condaenvs/
    (root) [root@af511ebe9357 /]# conda info --envs
    # conda environments:
    #
    devops                   /condaenvs/devops
    machine_learning         /condaenvs/machine_learning
    so                       /condaenvs/so
    statistics               /condaenvs/statistics
    throwaway                /condaenvs/throwaway
    root                  *  /conda
    
    (root) [root@7d75c8c6e873 /]# cat $HOME/.condarc 
    envs_dirs:
      - /condaenvs/
    
    (root) [root@7d75c8c6e873 /]# source activate statistics
    (statistics) [root@7d75c8c6e873 /]#
    

    On Windows:

    (root) C:\Users\nwani>dir F:\condaenvs
     Volume in drive F has no label.
     Volume Serial Number is 2B02-4CAF
    
     Directory of F:\condaenvs
    
    03/10/2017  02:06 PM    <DIR>          .
    03/10/2017  02:04 PM    <DIR>          ..
    03/10/2017  02:05 PM    <DIR>          devops
    03/10/2017  02:05 PM    <DIR>          so
    03/10/2017  02:06 PM    <DIR>          machine_learning
    03/10/2017  02:06 PM    <DIR>          statistics
    03/10/2017  02:06 PM    <DIR>          throwaway
                   0 File(s)              0 bytes
                   7 Dir(s)  36,200,026,112 bytes free
    
    (root) C:\Users\nwani>conda info --envs
    # conda environments:
    #
    root                  *  C:\Users\nwani\AppData\Local\Continuum\Miniconda2
    (root) C:\Users\nwani>conda config --add envs_dirs F:\condaenvs
    
    (root) C:\Users\nwani>conda info --envs
    # conda environments:
    #
    devops                   F:\condaenvs\devops
    machine_learning         F:\condaenvs\machine_learning
    so                       F:\condaenvs\so
    statistics               F:\condaenvs\statistics
    throwaway                F:\condaenvs\throwaway
    root                  *  C:\Users\nwani\AppData\Local\Continuum\Miniconda2
    
    
    (root) C:\Users\nwani>type %USERPROFILE%\.condarc
    envs_dirs:
      - F:\condaenvs
    
    (root) C:\Users\nwani>activate statistics
    
    (statistics) C:\Users\nwani>