简体   繁体   中英

Python running version 2.7 despite in a conda 3.8 environment

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM