146
 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?

5
  • 2
    Did you check your env folder? Mine was empty because i didnt provide a python version. If its empty gets activated but theres no python.
    – Julian
    Commented Nov 4, 2019 at 16:28
  • 1
    use this in your cmd: activate <envname>
    – Swapnil
    Commented Sep 9, 2020 at 22:57
  • 1
    For others who are experiencing this problem, the problem could also be this known bug: github.com/conda/conda/issues/9392 Commented Oct 1, 2020 at 18:47
  • Closing the current terminal and opening another one worked for me. Commented Dec 12, 2021 at 1:16
  • As @Julian mentions, I discovered that if I didn't create the environment with an explicit Python version then it simply defaults to something like /usr/bin/python rather than using the base env Python version. This is an unexpected new behavior that seems more like a bug. Commented Jul 2, 2022 at 19:50

28 Answers 28

160

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.

11
  • 1
    Then you need to add that requirement into your post.
    – darthbith
    Commented Nov 13, 2017 at 19:23
  • 2
    Also, according to this post, source is the correct command: superuser.com/a/84624/229278 You might need to install some additional dependencies: superuser.com/a/1235985/229278
    – darthbith
    Commented Nov 13, 2017 at 19:28
  • 36
    I found this question after getting CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. on windows. The fix is to use activate ... instead of conda activate ...
    – cedd
    Commented Jun 6, 2018 at 13:20
  • 1
    @darthbith. It's your answer, and I'm not a python expert, so do what you think is best. However, I have conda 4.5.4 on windows, and for me conda activate ... returns the CommandNotFoundError, whereas activate ... works as I would expect.
    – cedd
    Commented Jun 7, 2018 at 10:33
  • 1
    @cedd Are you using Powershell? Powershell is not supported: github.com/conda/conda/issues/626 You have to use the Anaconda Prompt. Also the release notes for conda 4.4 explicitly say that conda activate is the new way.
    – darthbith
    Commented Jun 7, 2018 at 13:30
80

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.

4
  • 1
    When I had the same error in another context, I followed www.greatytc.com/questions/44537131/… and there the answer of @User1024, adding a Path variable. Commented May 20, 2020 at 19:53
  • 3
    Wow! Had tried 1000 things, but FINALLY your tip worked. I just had to start my bat file with CALL conda.bat activate <my conda env name>.
    – Lucas925
    Commented Nov 5, 2020 at 2:39
  • 3
    After performing conda init in my cmd, conda activate worked, thanks the answer Commented Jan 17, 2021 at 15:22
  • Tkx brow, it solved my issue. Commented Aug 16, 2022 at 19:58
37

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)

3
  • 1
    Note that you need to have administrator privileges to accomplish this. If you add the path using the process above without admin privileges, it will not raise an error. However, if you close and re-open the command prompt, and run echo %PATH%, your change will not be there.
    – Foggy
    Commented Aug 11, 2020 at 16:24
  • @Foggy You can also add the Anaconda\Scripts PATH to your "user environment variables" without having admin rights (both on Win 7 & Win 10). These will then "persist" for new command prompts (after the first log-out / restart of your machine).
    – stephinity
    Commented Aug 14, 2020 at 8:31
  • @stephinity thanks this is the only solution that worked for me, on Windows 10 environment.
    – mnm
    Commented Oct 6, 2021 at 7:57
35

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
1
  • Worked, miniconda users use this source ~/miniconda3/etc/profile.d/conda.sh
    – 27px
    Commented Jun 11, 2023 at 6:22
20
  • run conda init in cmd
  • restart cmd
  • run conda activate envName
18

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.

2
  • 1
    It worked for me , the best solution I've found until now.(I'm using Google Cloud Platform).
    – Mahajna
    Commented Nov 22, 2021 at 16:37
  • this worked for me in 09/2023 Commented Sep 27, 2023 at 3:14
12
conda init

Run this in command prompt.

Worked for me.

11

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.

10

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.

2
  • 7
    The above instructions assume Mac/Linux env with the reference to a Bash or Bourne variant shell. What about for the standard Windows CMD shell? My miniconda3/etc/profile.d folder only has conda.sh and conda.csh files, but no Windows conda.bat version. Does one exist to support these instructions? Thanks.
    – okorng
    Commented May 1, 2018 at 6:30
  • 5
    I followed these instructions and I'm still getting that error, even though conda seems to be working otherwise. It's very strange.
    – szeitlin
    Commented Sep 7, 2018 at 0:28
9

Try this:

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

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

1
  • This is an answer for installations where there is no home folder as well. Sometimes there's only a root "user" and no home directory. Just add the path to miniconda/bin or anaconda3/bin (whereever you might have installed it) to $PATH and it should start running. e.g. export PATH=/root/minconda3/bin:$PATH
    – nlhnt
    Commented Feb 17, 2021 at 14:47
5

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

1
  • Thanks. In Powershell on Windows 10, nothing happened, no error message but also no environment activation. Using the "anaconda prompt" worked.
    – tcmb
    Commented Mar 17, 2020 at 13:57
4

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

3

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

3

As of October 2023, I installed Anaconda and created a new environment. IT worked perfectly fine from the windows PowerShell. It showed that I could now activate the environment with Conda activate but when I ran the command, it didn't work.

All I had to do was run the following command in windows PowerShell (as Jordan has mentioned):

conda init

After that, the windows PowerShell will show you a notice to restart the PowerShell, once I restarted it, it was working fine, and I was able to activate/deactivate my environments properly.

2

Just use this command in your cmd:

activate <envname>

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

2

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

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Mar 14, 2022 at 18:34
2

For windows, Use the Anaconda Powershell Prompt and conda command to activate the virtual environment

enter image description here

2
  • "Use the Anaconda Powershell Prompt" to do what?
    – miken32
    Commented Aug 9, 2022 at 16:12
  • 1
    This is what worked for me. Just use the Anaconda Prompt shell to do all command you would otherwise use in CMD. Windows 11 user here. Commented Jan 4, 2023 at 9:09
1

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

1

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.

1

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

1

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.

1
  • This is awesome
    – Travis
    Commented May 1, 2022 at 12:58
0

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.

0

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.

0

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.

0

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.

0

For using anaconda activate in Windows cmd/terminal
just simple Run as Administrator

0

I was also getting the error

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.

even after I had used conda init bash and restarted my shell.

In the end, it turned out that I had not activated the conda base environment first, so my generated environment was lacking a Python version. When using

conda activate base

before creating the new environment, it worked for me.

The tell-tale sign is that (base) is not showing in your prompt when you create your new environment.

-3

set-executionpolicy remotesigned Set-ExecutionPolicy unrestricted

1
  • 1
    Please add formatting and an explanation.
    – user16442705
    Commented Aug 3, 2021 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.