简体   繁体   中英

I can not activate virtual environment in conda

I create a virtual environment with conda

$ conda create test_env numpy .....

It gets created successfully.

$ conda env list
# conda environments:
#
base                  *  /home/myname/anaconda3
my_project_env           /home/myname/anaconda3/envs/my_project_env
test_env                 /home/myname/anaconda3/envs/test_env

but I can not activate it

$ source activate my_project_env

returns - activate: No such file or directory

The only place I find activate is within the whole anaconda3 is in /common folder

source anaconda3/envs/my_project_env/lib/python3.6/venv/scripts/common/activate my_project_env

When I run it with this path I get VENV_PROMPT "kind of environment" but when I check libraries with pip list it returns a global list of installed libraries instead of the selected few.

$ source anaconda3/envs/my_project_env/lib/python3.6/venv/scripts/common/activate my_project_env
__VENV_PROMPT__myname@box:~$ pip3 list

I met with the same problem. It is because I have changed the system's $PATH variable from anaconda's main bin directory to the environment's bin directory. Actually, the activate's path is under /home/users/anaconda3/bin/. So I just use the following command to make a link between the two bin directories:

ln -s /home/userName/anaconda3/bin/activate /home/userName/anaconda3/envs/envName/bin/activate
ln -s /home/userName/anaconda3/bin/deactivate /home/userName/anaconda3/envs/envName/bin/deactivate

Try to use this command activate your conda environment:

source activate /home/myname/anaconda3/envs/my_project_env

Recommended command to create environment with python version 2.7 :

conda create -n my_project_env python=2.7

Check your conda version

conda -V

Create virtual environment for your project

conda create -n yourenvname python=x.x anaconda

To activate your virtual environment

source activate yourenvname

As others have mentioned, it may be a PATH issue. However, if you're still able to run other conda commands then you may need to either conda update conda or delete conda and reinstall. In my case, I was running miniconda which I believe simply did not contain the activate binary.

Running conda activate instead of source activate solved my issues.

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