Conda: Creating a virtual environment

 ̄綄美尐妖づ 提交于 2019-11-29 00:56:46

问题


I'm trying to create a virtual environment. I've followed steps from both Conda and Medium.

Everything works fine until I need to source the new environment.

conda info -e

# conda environments:
#
base                  *  /Users/fwrenn/anaconda3
test_env                 /Users/fwrenn/anaconda3/envs/test_env

source ~/anaconda3/bin/activate test_env
_CONDA_ROOT=/Users/fwrenn/anaconda3: Command not found.
Badly placed ()'s.

I can't figure out the problem. Searching on here has solutions that say adding lines to your bash_profile, but I don't work in bash, only csh. It LOOKS like it's unable to build the directory path in activate.

My particulars:

OSX
python --version
Python 3.6.3 :: Anaconda custom (64-bit)
conda --version
conda 4.4.7

回答1:


Not sure what causes the problem in your case, but code below works for me without any issues (OSX, the same version of conda as yours).

Creation of the environment

conda create -n test_env python=3.6.3 anaconda

Some explanation if documentation of conda create is not clear:

  • -n test_env sets name of the environment to test_env

  • python=3.6.3 anaconda says that you want to use in this environment python in version 3.6.3 (exactly the one you have, you can use different one if you need) and package anaconda. You can put there all the things you need, separated with spaces, e.g. sqlite matplotlib requests and specify their versions the same way as for python.

Activation

conda activate test_env

Deactivation

conda deactivate

Getting rid of it

conda remove -n test_env --all



回答2:


I was able to solve my problem. Executing the source activate test_env command wasn't picking up my .bash_profile, I normally work in tcsh. Simply starting a subprocess in bash was enough to get activate working. I guess I assumed, incorrectly, that the activate command would start a child process in bash and use bash environment variables.

> conda info -e
> # conda environments:
> #
> base                  *  ~/anaconda3
> test_env                 ~/anaconda3/envs/test_env
> bash
~$ source ~/anaconda3/bin/activate test_env
(test_env) ~$
(test_env) ~$ conda info -e
# conda environments:
#
test_env              *  ~/anaconda3/envs/test_env
root                     ~/anaconda3


来源:https://stackoverflow.com/questions/48174935/conda-creating-a-virtual-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!