问题:如何激活Anaconda环境

我在Windows 8上,使用Anaconda 1.7.5 64bit。

我创建了一个新的Anaconda环境

conda create -p ./test python=2.7 pip

来自C:\Pr\TEMP\venv\

效果很好(有一个带有新python发行版的文件夹)。康达告诉我输入

activate C:\PR\TEMP\venv\test

激活环境,但是返回:

No environment named "C:\PR\temp\venv\test" exists in C:\PR\Anaconda\envs

如何激活环境?我究竟做错了什么?

I’m on Windows 8, using Anaconda 1.7.5 64bit.

I created a new Anaconda environment with

conda create -p ./test python=2.7 pip

from C:\Pr\TEMP\venv\.

This worked well (there is a folder with a new python distribution). conda tells me to type

activate C:\PR\TEMP\venv\test

to activate the environment, however this returns:

No environment named "C:\PR\temp\venv\test" exists in C:\PR\Anaconda\envs

How can I activate the environment? What am I doing wrong?


回答 0

如果发生这种情况,则需要为您的环境设置PATH(以便从环境和Windows上的Scripts \中获取正确的Python)。

假设您使用以下方法创建了一个名为py33的环境:

conda create -n py33 python=3.3 anaconda

在默认情况下,这里是在Anaconda \ envs中创建的文件夹,因此您需要将PATH设置为:

set PATH=C:\Anaconda\envs\py33\Scripts;C:\Anaconda\envs\py33;%PATH%

现在它应该可以在命令窗口中工作:

activate py33

上面的行是Windows,等同于Mac和Linux教程中通常显示的代码:

$ source activate py33

更多信息:https : //groups.google.com/a/continuum.io/forum/#!topic/ anaconda/ 8T8i11gO39U

anaconda是否为每个新环境创建一个单独的PYTHONPATH变量?

If this happens you would need to set the PATH for your environment (so that it gets the right Python from the environment and Scripts\ on Windows).

Imagine you have created an environment called py33 by using:

conda create -n py33 python=3.3 anaconda

Here the folders are created by default in Anaconda\envs, so you need to set the PATH as:

set PATH=C:\Anaconda\envs\py33\Scripts;C:\Anaconda\envs\py33;%PATH%

Now it should work in the command window:

activate py33

The line above is the Windows equivalent to the code that normally appears in the tutorials for Mac and Linux:

$ source activate py33

More info: https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/8T8i11gO39U

Does `anaconda` create a separate PYTHONPATH variable for each new environment?


回答 1

使用cmd代替Powershell! 我花了2个小时才切换到cmd,然后才起作用!

创建环境:

conda create -n your_environment_name

查看conda环境列表:

conda env list

激活您的环境:

conda activate your_environment_name

那是所有人

Use cmd instead of Powershell! I spent 2 hours before I switched to cmd and then it worked!

create Environment:

conda create -n your_environment_name

see list of conda environments:

conda env list

activate your environment:

conda activate your_environment_name

That’s all folks


回答 2

请注意,用于激活环境的命令在Conda 4.4版中已更改。激活一个环境的推荐的方法是现在conda activate myenv,而不是source activate myenv。要启用新语法,您应该修改 .bashrc文件。该行当前显示类似

export PATH="<path_to_your_conda_install>/bin:$PATH"

应该改为

. <path_to_your_conda_install>/etc/profile.d/conda.sh

这只会将conda命令添加到路径,而尚未激活base环境(以前称为root)。为此,添加另一行

conda activate base

在第一个命令之后。请参阅Anaconda自2017年12月以来的博客文章中的所有详细信息。(我认为该页面目前缺少两行之间的换行符.../conda.shconda activate base)。

(此答案对Linux有效,但对Windows和Mac也可能适用)

Note that the command for activating an environment has changed in Conda version 4.4. The recommended way of activating an environment is now conda activate myenv instead of source activate myenv. To enable the new syntax, you should modify your .bashrc file. The line that currently reads something like

export PATH="<path_to_your_conda_install>/bin:$PATH"

Should be changed to

. <path_to_your_conda_install>/etc/profile.d/conda.sh

This only adds the conda command to the path, but does not yet activate the base environment (which was previously called root). To do also that, add another line

conda activate base

after the first command. See all the details in Anaconda’s blog post from December 2017. (I think that this page is currently missing a newline between the two lines, it says .../conda.shconda activate base).

(This answer is valid for Linux, but it might be relevant for Windows and Mac as well)


回答 3

以前所有的答案似乎都是过时的。

conda activateconda4.4和4.6中引入。

conda activate:重新激活了环境激活的逻辑和机制。与康达4.4,conda activate并且conda deactivate是现在用于激活和停用环境的首选命令。您会发现它们比以前的conda版本中的source activateand source deactivate命令更加灵活。该conda activate命令还具有(1)在所有OS,shell 和平台上通用的优势,以及(2)与其他包(例如python virtualenv的Activate脚本)中的脚本没有路径冲突。

例子

conda create -n venv-name python=3.6
conda activate -n venv-name
conda deactivate

这些新的子命令在“ Aanconda提示”和“ Anaconda Powershell提示”中自动可用。要conda activate每个shell(普通cmd.exe和powershell)中使用,请在Windows的每个shell中检查暴露conda命令

参考资料

All the former answers seem to be outdated.

conda activate was introduced in conda 4.4 and 4.6.

conda activate: The logic and mechanisms underlying environment activation have been reworked. With conda 4.4, conda activate and conda deactivate are now the preferred commands for activating and deactivating environments. You’ll find they are much more snappy than the source activate and source deactivate commands from previous conda versions. The conda activate command also has advantages of (1) being universal across all OSes, shells, and platforms, and (2) not having path collisions with scripts from other packages like python virtualenv’s activate script.

Examples

conda create -n venv-name python=3.6
conda activate -n venv-name
conda deactivate

These new sub-commands are available in “Aanconda Prompt” and “Anaconda Powershell Prompt” automatically. To use conda activate in every shell (normal cmd.exe and powershell), check expose conda command in every shell on Windows.

References


回答 4

从错误消息中可以看到,您指定的路径是错误的。像这样尝试:

activate ..\..\temp\venv\test

但是,当我需要安装Anaconda时,我从这里下载了它并将其安装到默认路径(C:\Anaconda),而不是将此路径放置到环境变量中,因此现在将Anacondas解释器用作默认路径。例如,如果您使用的是PyCharm,则可以在那里直接指定解释器。

As you can see from the error message the paths, that you specified, are wrong. Try it like this:

activate ..\..\temp\venv\test

However, when I needed to install Anaconda, I downloaded it from here and installed it to the default paths (C:\Anaconda), than I put this path to the environment variables, so now Anacondas interpreter is used as default. If you are using PyCharm, for example, you can specify the interpreter there directly.


回答 5

以下是它对我的工作方式

  1. C:\ Windows \ system32>设置CONDA_ENVS_PATH = d:\您的\位置
  2. C:\ Windows \ system32> conda信息

显示新的环境路径

  1. C:\ Windows \ system32> conda创建-n YourNewEnvironment –clone = root

克隆默认的根环境

  1. C:\ Windows \ system32>激活YourNewEnvironment

停用环境“ d:\ YourDefaultAnaconda3” …停用环境“ d:\ your \ location \ YourNewEnvironment” …

  1. [YourNewEnvironment] C:\ Windows \ system32> conda信息-e

康达环境:

YourNewEnvironment
* d:\ your \ location \ YourNewEnvironment

根d:\ YourDefaultAnaconda3

Below is how it worked for me

  1. C:\Windows\system32>set CONDA_ENVS_PATH=d:\your\location
  2. C:\Windows\system32>conda info

Shows new environment path

  1. C:\Windows\system32>conda create -n YourNewEnvironment –clone=root

Clones default root environment

  1. C:\Windows\system32>activate YourNewEnvironment

Deactivating environment “d:\YourDefaultAnaconda3″… Activating environment “d:\your\location\YourNewEnvironment”…

  1. [YourNewEnvironment] C:\Windows\system32>conda info -e

conda environments: #

YourNewEnvironment
* d:\your\location\YourNewEnvironment

root d:\YourDefaultAnaconda3


回答 6

我曾尝试用Jenkins job(bash)激活env conda activate base ,但是失败了,所以在尝试了很多之后,这个对我有用(CentOS 7):

source /opt/anaconda2/bin/activate base

I’ve tried to activate env from Jenkins job (in bash) with conda activate base and it failed, so after many tries, this one worked for me (CentOS 7) :

source /opt/anaconda2/bin/activate base

回答 7

假设您的环境名称为‘demo’,并且您正在使用anaconda并想创建一个虚拟环境:

(如果您想要python3)

    conda create -n demo python=3

(如果您想要python2)

    conda create -n demo python=2

运行上述命令后,您必须通过以下命令激活环境:

    source activate demo 

let’s assume your environment name is ‘demo’ and you are using anaconda and want to create a virtual environment:

(if you want python3)

    conda create -n demo python=3

(if you want python2)

    conda create -n demo python=2

After running above command you have to activate the environment by bellow command:

    source activate demo 

回答 8

对我来说,使用Anaconda Prompt代替cmd或PowerShell是关键。

在Anaconda Prompt中,我要做的就是 activate XXX

For me, using Anaconda Prompt instead of cmd or PowerShell is the key.

In Anaconda Prompt, all I need to do is activate XXX


回答 9

我也有相同的想法,似乎已在源代码中进行了修复。

I was having the same, a fix seems to have been made in the source.


回答 10

正如@Simba正确回答的那样,自4.6起conda env发生了变化。Conda activate (env-name)彻底推翻source activate (env-name),但并非没有挑战。conda activate经常强迫你的环境建立基础,让你看到类似的东西(基础)。因此,将大量错误抛给您。这也可能是因为auto_activate_base设置为True。

您可以使用以下命令进行检查

conda config --set auto_activate_base False

source ~/.bashrc

要重新激活使用此

conda config --set auto_activate_base True

source ~/.bashrc

just as @Simba has rightly answered alot has changed in the conda env since 4.6. Conda activate (env-name) overthrew source activate (env-name) for good but not without it own challenges. conda activate oftentimes force your environment to base and make u see something like (base). Therefore throwing loads of error back at you. This can also be because auto_activate_base is set to True.

You can check this by using the following command

conda config --set auto_activate_base False

source ~/.bashrc.

And To reactivate use this

conda config --set auto_activate_base True

source ~/.bashrc


回答 11

窗口: conda激活environment_name

Mac:conda激活environment_name

Window: conda activate environment_name

Mac: conda activate environment_name


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。