问题:如何激活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
回答 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 activate
在conda
4.4和4.6中引入。
conda activate
:重新激活了环境激活的逻辑和机制。与康达4.4,conda activate
并且conda deactivate
是现在用于激活和停用环境的首选命令。您会发现它们比以前的conda版本中的source activate
and 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
以下是它对我的工作方式
- C:\ Windows \ system32>设置CONDA_ENVS_PATH = d:\您的\位置
- C:\ Windows \ system32> conda信息
显示新的环境路径
- C:\ Windows \ system32> conda创建-n YourNewEnvironment –clone = root
克隆默认的根环境
- C:\ Windows \ system32>激活YourNewEnvironment
停用环境“ d:\ YourDefaultAnaconda3” …停用环境“ d:\ your \ location \ YourNewEnvironment” …
- [YourNewEnvironment] C:\ Windows \ system32> conda信息-e
康达环境:
YourNewEnvironment
* d:\ your \ location \ YourNewEnvironment
根d:\ YourDefaultAnaconda3
Below is how it worked for me
- C:\Windows\system32>set CONDA_ENVS_PATH=d:\your\location
- C:\Windows\system32>conda info
Shows new environment path
- C:\Windows\system32>conda create -n YourNewEnvironment –clone=root
Clones default root environment
- C:\Windows\system32>activate YourNewEnvironment
Deactivating environment “d:\YourDefaultAnaconda3″… Activating environment “d:\your\location\YourNewEnvironment”…
- [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 . 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
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。