Python Conda:创建虚拟环境

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48174935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:35:00  来源:igfitidea点击:

Conda: Creating a virtual environment

pythonmacosvirtualenvironmentconda

提问by Forrest

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

我正在尝试创建一个虚拟环境。我遵循了CondaMedium 的步骤。

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.

我无法弄清楚问题所在。在这里搜索有解决方案说向您的 bash_profile 添加行,但我不在 bash 中工作,只在 csh 中工作。看起来它无法在activate.

My particulars:

我的资料:

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

采纳答案by Forrest

I was able to solve my problem. Executing the source activate test_envcommand wasn't picking up my .bash_profile, I normally work in tcsh. Simply starting a subprocess in bashwas enough to get activateworking. I guess I assumed, incorrectly, that the activatecommand would start a child process in bashand use bashenvironment variables.

我能够解决我的问题。执行source activate test_env命令并没有拿起我的.bash_profile,我通常在tcsh. 只需在其中启动一个子流程bash就足以开始activate工作。我想我错误地假设该activate命令将启动子进程bash并使用bash环境变量。

> 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

回答by machnic

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).

不确定是什么导致了您的问题,但下面的代码对我有用,没有任何问题(OSX,与您的 conda 版本相同)。

Creation of the environment

创造环境

conda create -n test_env python=3.6.3 anaconda

Some explanation if documentationof conda createis not clear:

如果一些解释文件conda create不明确:

  • -n test_envsets name of the environment to test_env

  • python=3.6.3 anacondasays that you want to use in this environment pythonin 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 requestsand specify their versions the same way as for python.

  • -n test_env将环境名称设置为test_env

  • python=3.6.3 anaconda说你想在这个环境中使用3.6.3版本的python(正是你所拥有的,如果需要,你可以使用不同的)并打包anaconda。你可以把你需要的所有东西放在那里,用空格分隔,例如,并以与python相同的方式指定它们的版本。sqlite matplotlib requests

Activation

激活

conda activate test_env

Deactivation

停用

conda deactivate

Getting rid of it

摆脱它

conda remove -n test_env --all

回答by Muhammad Shabin

Check conda is installed

检查 conda 是否已安装

conda -V

Check conda is up to date..

检查 conda 是否是最新的..

conda update conda

Create a virtual environment...

创建虚拟环境...

conda create -n yourenvname python=x.x anaconda

Activate your virtual environment...

激活您的虚拟环境...

source activate yourenvname

Install additional Python packages to a virtual environment....

将其他 Python 包安装到虚拟环境中....

conda install -n yourenvname [package]

Deactivate your virtual environment...

停用您的虚拟环境...

source deactivate

Delete virtual environment...

删除虚拟环境...

conda remove -n yourenvname -all