I want to activate the anaconda virtual env on the command line. And I used the commands below to activate it.
source activate py368 (or conda activate py368)
(py368) **@** $
It seemed the virtual env had been activated, but when I ran python codes, the command line just called the system version of python.
(py368) **@** $ python
import sys
sys.executable
The output showed that the version of python was not conda virtual env.
'/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6'
But I found I can activate the virtual env using the code below, which is quite inconvenient.
source /Users/**/anaconda3/bin/activate
conda activate py368
/Users/**/anaconda3/envs/py368/bin/python
This method can activate the virtual env as I want.
sys.executable
'/Users/**/anaconda3/envs/py368/bin/python'
Is there any way to solve the problem to make the activate work fine?
Update:
After activating conda virtual env, the virtual env bin folder was added to the PATH, but it still cannot work.
$PATH
-bash: `/Users/**/anaconda3/envs/py368/bin:/Users/**/anaconda3/condabin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin: No such file or directory`
Final Solution:
I found the solution to my problem.
My ~/.bash_profile contains these few sentences, and after commenting them, I can activate the conda virtual env. Then I put python
in the command, it will call the virtual version of Python.
But I don't understand why this happened? Just because I changed the system version of Python?
#PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
#export PATH
#alias #python="/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6"