Python running version 2.7 despite in a conda 3.8 environment

404 views Asked by At

I created and activated a conda environment with python 3.8. When calling python it systematically runs Python version 2.7 instead of 3.8.

(base) $ conda create -n py38 python=3.8

(base) $ conda activate py38

(py38) $ python --version
Python 2.7.16

(py38) $ which python
/usr/bin/python

(py38) $ which python3.8
/Users/xyz/opt/anaconda3/envs/py38/bin/python3.8

In $PATH there is effectively /usr/bin but I'm surprised that conda doesn't override that while the environment is running. Also, there is no python alias to be found in any of the possible configuration files (.bashrc, .zshrc, .bash_profile, .profile or any other).

How can I get the python command to correctly run Python 3.8 while the py38 env is active?

Generally speaking, how to get conda to run the correct Python version "once and for all" in any new environment I would create in the future?

1

There are 1 answers

1
Philippe On

You need to make sure when you are in (py38) by :

echo $PATH

that /Users/xyz/opt/anaconda3/envs/py38/bin is before /usr/bin

then run

cd /Users/xyz/opt/anaconda3/envs/py38/bin
ln -fs python3.8 python3
ln -fs python3   python