'Conda activate not working?

 gonzo  ~/a/packages  conda env list
# conda environments:
#
ppo_latest               /nohome/jaan/abhishek/anaconda3/envs/ppo_latest
root                  *  /nohome/jaan/abhishek/anaconda3

 gonzo  ~/a/packages  conda activate ppo_latest
 gonzo  ~/a/packages  which python                                                                                     (ppo_latest)
/nohome/jaan/abhishek/anaconda3/bin/python
 gonzo  ~/a/packages  conda deactivate                                                                                 (ppo_latest)
 gonzo  ~/a/packages  which python
/nohome/jaan/abhishek/anaconda3/bin/python

The environment gets activated without an error. Then we check which python it is referring to it. It is doesn't change, why?



Solution 1:[1]

As of conda 4.4, the command

conda activate <envname>

is the same on all platforms. The procedure to add conda to the PATH environment variable for non-Windows platforms (on Windows you should use the Anaconda Prompt), as well as the change in environment activation procedure, is detailed in the release notes for conda 4.4.0.


For conda versions older than 4.4, command is either

source activate <envname>

on Linux and macOS or

activate <envname>

on Windows. You need to remove the conda.

Solution 2:[2]

Functions are not exported by default to be made available in subshells. I'd recommend you do:

source ~/anaconda3/etc/profile.d/conda.sh
conda activate my_env

In the commands above, replace ~/anaconda3/ with the path to your miniconda / anaconda installation.

Solution 3:[3]

I just ran into a similar issue. Recently started developing on windows, so getting used to the PowerShell. Ironically when trying to use 'conda activate ' in Git-bash i got the error

$ conda activate obf

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - cmd.exe
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'. 

Running the command in my PowerShell (elevated) as instructed did the trick for me.

conda init powershell 

This should be true across all terminal environments, just strange PowerShell didn't return this error itself.

Solution 4:[4]

To use "conda activate" via Windows CMD, not the Anaconda Prompt:
(in response to okorng's question, although using the Anaconda Prompt is the preferred option)

First, we need to add the activate.bat script to your path:
Via CMD:

set PATH=%PATH%;<your_path_to_anaconda_installation>\Scripts

Or via Control Panel, open "User Accounts" and choose "Change my environment variables".

Then calling directly from Windows CMD:

activate <environment_name>

without using the prefix "conda".

(Tested on Windows 7 Enterprise with Anaconda3-5.2.0)

Solution 5:[5]

The anaconda functions are not exported by default, it can be done by using the following command:

source ~/anaconda3/etc/profile.d/conda.sh

conda activate my_env

Solution 6:[6]

I just created a new environment with conda and things are different. My sys.path was not correct for a bit until I figured out way.

As a result, I want to point out for anyone else confused by a change in conda, that if you have upgraded conda and created an environment, it will now tell you (as opposed to previous behavior):

# To activate this environment, use
#
#     $ conda activate test
#
# To deactivate an active environment, use
#
#     $ conda deactivate

Thus, the new way to activate/deactivate environments is to do it like the above.

Indeed, if you upgrade from an older version of conda and you try the above, you may see the following helpful message (which I did):

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with

    $ echo ". ~/anaconda/etc/profile.d/conda.sh" >> ~/.bash_profile

or, for all users, enable conda with

    $ sudo ln -s ~/anaconda/etc/profile.d/conda.sh /etc/profile.d/conda.sh

The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH.  To do so, run

    $ conda activate

in your terminal, or to put the base environment on PATH permanently, run

    $ echo "conda activate" >> ~/.bash_profile

Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bash_profile file.  You should manually remove the line that looks like

    export PATH="~/anaconda/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bash_profile file! ^^^

Changing the above fixed my issues with sys.path in activated conda environments.

Solution 7:[7]

As of conda 4.10.1, here is what worked for me using the Git Bash terminal in Sublime text 3 (same for cmd and Git cmd) on Windows:

$ source activate env_name

for me: $ activate env_name and $ conda activate env_name did not work!

to check the list of activated conda environments, in my case I use

$ conda env list

or

$ conda info --envs

the activated environment is preceded by *

note that I have already added anaconda to my path.

Solution 8:[8]

Try this:

export PATH=/home/your_username/anaconda3/bin:$PATH
in ~/.bashrc

Then source ~/.bashrc This works for me for the same problem.

Solution 9:[9]

If your console does not show (base) after running conda activate base, then try running:

conda init

Then running conda activate <your_env> should show the name of (<your_env>) at the beginning of the shell prompt.

This worked for me on Windows. My PATH environment variable was set properly so conda activate base did not raise any error but quietly failed.

Solution 10:[10]

In the windows environment use "anaconda prompt" instead of "command prompt".

Solution 11:[11]

Just use this command in your cmd:

activate <envname>

Works like charm! (worked for windows, don't know about mac)

Solution 12:[12]

go settings and change "shell path" to "cmd" from power shell. i'm using pycharm on windows 10, and that fixed my prolem. settings>tools>terminal>shell path>cmd

Solution 13:[13]

In my case the change of default terminal to command promt (cmd.exe) did a trick. VS Code - Windows 10

Solution 14:[14]

This solution is for those users who do not want to set PATH.

Sometimes setting PATH may not be desired. In my case, I had Anaconda installed and another software with a Python installation required for accessing the API, and setting PATH was creating conflicts which were difficult to resolve.

Under the Anaconda directory (in this case Anaconda3) there is a subdirectory called envs where all the environments are stored. When using conda activate some-environment replace some-environment with the actual directory location of the environment.

In my case the command is as follows.

conda activate C:\ProgramData\Anaconda3\envs\some-environment

Solution 15:[15]

For windows, Use the Anaconda Powershell Prompt

enter image description here

Solution 16:[16]

Here's what worked for me using the Git Bash terminal in VS Code on windows in succinct steps:

  1. source activate env-name - You should see your line appended by the (base) tag now.

  2. After calling on source activate, I've found following conda activate commands to work: i.e. conda activate env2-name

What didn't work for Git Bash (as a VS Code terminal) for me: activate env-name and conda activate env-name.

Not exactly sure why this specific behaviour occurs on the Git Bash terminal on VS Code, but the accepted answer + this stackoverflow question I've found might provide clues.

Solution 17:[17]

After installing conda in Linux if you are trying to create env just type bash and hit Enter later you can create env

Solution 18:[18]

I changed my shell from bash to zsh according to Apple prompt message and restarted the terminal, and it works for me after doing this.

Solution 19:[19]

I had same issue but For linux this worked : in terminal Type:

$ bash
$ conda init
$ cd /path_that_include_env_dir
$ conda activate ./<env_name>

or

$ conda activate /env_path

"env_path" is full environment path as : /home/usr/env_dir

To check environments list and their paths $ conda env list

Solution 20:[20]

If nothing works for you, you can specify the full path of your python environment setup by conda.

For me, I set up an environment called "testenv" using conda.

I searched all python environments using

whereis python | grep 'miniconda'

It returned a list of python environments. Then I ran my_python_file.py using the following command.

~/miniconda3/envs/testenv/bin/python3.8 my_python_file.py

You can do the same thing on windows too but looking up for python and conda python environments is a bit different.

Solution 21:[21]

Have you tried with Anaconda command prompt or, cmd it works for me. Giving no error and activation is not working in PowerShell may be some path issue.

Solution 22:[22]

Hello let me share what worked for me. (WINDOWS USERS)

  1. Add conda to path(that is to your environment variables - the scripts folder to be precise) i.e. C:\Users\kboys\anaconda3\Scripts
  2. Reopen your cmd, type activate and the name of your target environment, i.e

$ activate <env_name>

$ activate tensorflow

Note this way you don't need to call conda.

Solution 23:[23]

I just created a new environment in miniconda, but when trying to activate it in VSCode's terminal, it gives this

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. If using 'conda activate' from a batch script, change your invocation to 'CALL conda.bat activate'.

Then I found in the VSCode settings this option, terminal.integrated.shellArgs:

Terminal options

By default, it is 'null', but changing it to 'Command Prompt', it made the 'conda activate [my env]' command in the VSCode terminal work.

Solution 24:[24]

  • run conda init in cmd
  • restart cmd
  • run conda activate envName