Skip to content Skip to sidebar Skip to footer

Conda Activate/deactivate Environment Breaking Path

I am finding that when I create a Conda environment source activate environment and then deactivate that environment source deactivate environment, my native bash commands no longe

Solution 1:

Most probably your conda environment is replacing the parameters and environment variables defined in your local bash profile. I am sure if you open a new environment(bash session), you will find everything is working fine.

I would suggest you add a command to reload bash profile after deactivating the environment, so that the profile variable values will again be applied. It should solve the problem.

Solution 2:

There are a few bugs in the activate/deactivate scripts, which I've fixed in versions I call activate.cygwin and deactivate.cygwin.

  • activate.cygwin: fixes 2 places where the conda command returns a string with a return "\r" at the end that confounds processing.

  • deactivate.cygwin: fixes conversion of /cygdrive/... to avoid error CondaValueError: Could not find environment: /cygdrivec:\Users\rjp\Anaconda2\envs...

I've posted the modified scripts to https://bitbucket.org/snippets/plevin/. See instructions at the top of activate.cygwin.

Solution 3:

The correct way to deactivate a conda environment is to run conda deactivate, rather than source deactivate environment

Source: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html?highlight=activate#deactivating-an-environment

Solution 4:

I use Git Bash in Windows 10 and encountered the same problem too. The previous answer does not work for me, probably because I don't have any path set in ~/.bash_profile and ~/.bashrc.

I checked my path variable in a fresh git bash, it looks like:

/c/Users/chen_x/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/chen_x/bin....(more)

After . C:/Users/chen_x/Miniconda3/Scripts/activate C:/Users/chen_x/Miniconda3 and . activate snowflakes, the path becomes:

/C/Users/chen_x/Miniconda3/envs/snowflakes:(blalbla..):C:\Users\chen_x\Miniconda3\Library\bin;C:\Users\chen_x\Miniconda3;....(more)

I assume that git bash does not recognize pathes like C:\program files..., then added the following line to C:/Users/chen_x/Miniconda3/Scripts/activate right after the last EXPORT PATH= command (about line 78):

export PATH="$($_CONDA_PYTHON -c "import re; p=re.sub(r'\\\', r'/', r'$PATH'); p=re.sub('(;|:)([A-Z]):', lambda m: ':/'+m.group(2).lower(), p); print(p)")"

It works.

By the way, I create a ~/condaenv script to start conda environment:

#!/bin/bash
. C:/Users/chen_x/Miniconda3/Scripts/activate C:/Users/chen_x/Miniconda3

It would be convinent to :

. ~/condaenv
. activate snowflakes

Post a Comment for "Conda Activate/deactivate Environment Breaking Path"