How to create conda environment with specific python version?

AKG picture AKG · Jun 22, 2019 · Viewed 29.2k times · Source

I have miniconda3 installed and since I would like to have an environment with python version 3.3.0, I create it via

conda create -n "myenv" python=3.3.0

However when I activate the environment via

conda activate myenv

python has version 2.7.15 and path

/usr/bin/python

and ipython has python version 3.6.8 and path

/home/myname/.local/bin/ipython

I can access the correct python with python3 which is at

/home/myname/miniconda3/envs/mattention/bin/python3

however, ipython3 has python version 3.6.8 again.

conda install python=3.3.0

left the situation unchanged.

A solution would be to open IPython via

python3 -m IPython

however, while this works fine for python here I get the error message

/home/myname/miniconda3/envs/mattention/bin/python3: No module named IPython

Is it possible to access with the commands python and ipython both python version 3.3.0 in that specific environment, i.e. not by setting an alias in the .bashrc?

EDIT:

Turns out that this problem does not occur if you select version 3.3 instead of 3.3.0 together with @ilmarinen's answer

conda create -n "myenv" python=3.3 ipython

everything works fine and python as well as ipython result to version python 3.3.5.

Answer

ilmarinen picture ilmarinen · Jun 22, 2019

You need to install ipython as well into your given environment

conda create -n "myenv" python=3.3.0 ipython

The conda environments are prepended to your PATH variable, so when you are trying to run the executable "ipython", Linux will not find "ipython" in your activated environment (since it doesn't exist there), but it will continue searching for it, and eventually find it wherever you have it installed.