Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 
like image 482
neversaint Avatar asked Apr 20 '16 03:04

neversaint


People also ask

Which Python is conda using?

Conda treats Python the same as any other package, so it is easy to manage and update multiple installations. Anaconda supports Python 3.7, 3.8, 3.9 and 3.10. The current default is Python 3.9.


2 Answers

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.)

like image 196
Tahlor Avatar answered Sep 29 '22 13:09

Tahlor


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.

like image 21
Raza Avatar answered Sep 29 '22 12:09

Raza