Conda activate not working?

Viewed 357675
 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?

25 Answers

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.

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.

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)

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

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.

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.

Try this:

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

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

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

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

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

Just use this command in your cmd:

activate <envname>

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

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

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

For windows, Use the Anaconda Powershell Prompt

enter image description here

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.

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

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.

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

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.

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.

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.

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.

conda init

Run this in command prompt.

Worked for me.

set-executionpolicy remotesigned Set-ExecutionPolicy unrestricted

Related