'Why Conda cannot call correct Python version after activating the environment?

I have the following conda environment under Linux:

$ conda info -e
# conda environments:
#
py33                     /u21/coyotito/.anaconda/envs/py33
root                  *  /u21/coyotito/.anaconda

And py33 is created with this command:

$ conda create -n py33 python=3.3 anaconda

The problem is when I activate py33 it still cannot call Python version 3.3.

[coyotito@pearl ~]$ source activate py33
(coyotito)[coyotito@pearl ~]$ python --version
Python 2.7.10 :: Anaconda 2.1.0 (64-bit)
(coyotito)[coyotito@pearl ~]$ conda info -e
# conda environments:
#
py33                     /u21/coyotito/.anaconda/envs/py33
root                  *  /u21/coyotito/.anaconda

Namely it still calling old python. Notice also that the prompt under bracket is not (py33).

(coyotito)[coyotito@pearl ~]$ which python
~/.anaconda/bin/python

Instead of python in new environment:

~/.anaconda/envs/py33/bin/python3.3

How can I resolve this issue?

Update

My PATH environment in ~/.bash_profile looks like this:

export PATH=$HOME/.anaconda/bin:$PATH


Solution 1:[1]

I had the exact same problem. Not sure what I did to get into that mess, but I solved it with a simple:

conda deactivate
conda activate foo_env

(If you have activated multiple environments, you may need to run conda deactivate multiple times.)

Solution 2:[2]

TLDR;

# deactivate Conda environment
# (until even base environment is deactivated)
conda deactivate
# activate your environment
conda activate your_env_name_goes_here

try this

Activate an environment A and then check the location of Python package by using the command below.

python -c "import sys; print(sys.executable)"

Activate another environment, let's say environment B and rerun the above python command. If conda isn't using the correct Python version then most likely running the above command will print the same path in both environments.

My conda installation wasn't using the correct version because I had activated my environment on top of the conda base environment.

Deactivating the base environment and then activating the environment I wanted, worked.

Solution 3:[3]

Landed here with this same issue, but by moving out of the anaconda executable directory, the correct python was called. I was in a directory that contained the python executable that was installed with Anaconda2.

Example:

(py35) C:\Anaconda>python --version
Python 2.7.11 :: Anaconda 4.0.0 (64-bit)

(py35) C:\Anaconda>cd ..

(py35) C:\>python --version
Python 3.5.2 :: Anaconda 4.2.0 (64-bit)

(py35) C:\>

Solution 4:[4]

So in my situation, a intern before me append anaconda path to path variable in /etc/profile, which override my conda setting in ~/.bashrc, simply removing those line in /etc/profile can help.

Solution 5:[5]

This only happens when you create an environment without specifying any additional packages. I am using Conda 4.10.3

Refer https://github.com/conda/conda/issues/9392#issuecomment-696897058

The following comment from the above link worked in my case:

I noticed that it works if i install a packet when i create the environment.

antony@antony-fedora : ~/Workspace/tmp : which python /usr/bin/python
antony@antony-fedora : ~/Workspace/tmp : conda create --name my_env 
antony@antony-fedora : ~/Workspace/tmp : conda activate my_env 
(my_env) antony@antony-fedora : ~/Workspace/tmp : which python
/usr/bin/python 
(my_env) antony@antony-fedora : ~/Workspace/tmp : conda create --name my_env pip  
(my_env) antony@antony-fedora : ~/Workspace/tmp : conda activate my_env 
(my_env) antony@antony-fedora : ~/Workspace/tmp : which python ~/anaconda3/envs/my_env/bin/python

Also, recommend adding conda deactivate to the end of your .zshenv or .bash_profile

Solution 6:[6]

With MacOS, I was facing a similar issue. I was able to resolve the issue by changing the python interpreter (appears on bottom left corner) within VS-code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 lwright
Solution 4 Chimaopen
Solution 5 wuerfelfreak
Solution 6 Akul Bansal