0

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"
Zac
  • 598
  • 6
  • 11
  • Possible duplicate of [How to run Conda?](https://stackoverflow.com/questions/18675907/how-to-run-conda) `source activate` is not recommended. Conda has a `conda init` command that will set up your shell (`bash` or others) so you don't have to do `source activate`. Recommended initialization is `conda activate`. – merv Oct 03 '19 at 14:20
  • @merv, the virtual env path is in the PATH, but it doesn't work. And I tried `conda activate`, still not work. – Zac Oct 04 '19 at 11:51

0 Answers0