Conda activate not working?

 gonzo  ~/a/packages  conda env list
# conda environments:
#
ppo_latest               /nohome/jaan/abhishek/anaconda3/envs/ppo_latest
root                  *  /nohome/jaan/abhishek/anaconda3


gonzo  ~/a/packages  conda activate ppo_latest
gonzo  ~/a/packages  which python                                                                                     (ppo_latest)
/nohome/jaan/abhishek/anaconda3/bin/python
gonzo  ~/a/packages  conda deactivate                                                                                 (ppo_latest)
gonzo  ~/a/packages  which python
/nohome/jaan/abhishek/anaconda3/bin/python

The environment gets activated without an error. Then we check which python it is referring to it. It is doesn't change, why?

381243 次浏览

从 Conda 4.4开始

conda activate <envname>

在所有平台上都是一样的。在非 Windows 平台的 PATH环境变量中添加 conda的过程(在 Windows 上,你应该使用蟒蛇提示符) ,以及环境激活过程的改变,在 conda 4.4.0的 释放通知书中有详细说明。


对于超过4.4的 conda 版本,command 是

source activate <envname>

on Linux and macOS or

activate <envname>

你需要删除 conda

我只是用 Conda 创造了一个新环境,事情就不一样了。我的 sys.path是不正确的一点,直到我找到了方法。

因此,我想对那些对 conda的改变感到困惑的人指出,如果你升级了 conda 并创建了一个环境,它现在会告诉你(与之前的行为相反) :

# To activate this environment, use
#
#     $ conda activate test
#
# To deactivate an active environment, use
#
#     $ conda deactivate

因此,新的激活/禁用环境的方法就是像上面那样做。

事实上,如果你从旧版本的 conda 升级并尝试上面的方法,你可能会看到以下有用的信息(我就是这么做的) :

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with


$ echo ". ~/anaconda/etc/profile.d/conda.sh" >> ~/.bash_profile


or, for all users, enable conda with


$ sudo ln -s ~/anaconda/etc/profile.d/conda.sh /etc/profile.d/conda.sh


The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH.  To do so, run


$ conda activate


in your terminal, or to put the base environment on PATH permanently, run


$ echo "conda activate" >> ~/.bash_profile


Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bash_profile file.  You should manually remove the line that looks like


export PATH="~/anaconda/bin:$PATH"


^^^ The above line should NO LONGER be in your ~/.bash_profile file! ^^^

更改上述修复了我的问题与 sys.path在激活的康达环境。

通过 Windows CMD,而不是蟒蛇提示符使用“ conda 激活”:
(在回答 okorn 的问题时,尽管使用蟒蛇提示符是更好的选择)

首先,我们需要将 activate.bat 脚本添加到路径中:
Via CMD: < br >

set PATH=%PATH%;<your_path_to_anaconda_installation>\Scripts

或通过控制面板,打开“用户帐户”,并选择“更改我的环境变量”。

然后直接从 Windows CMD 呼叫:

activate <environment_name>

没有使用前缀“ conda”。

(使用 Anaconda3-5.2.0在 Windows 7 Enterprise 上进行测试)

试试这个:

export PATH=/home/your_username/anaconda3/bin:$PATH
in ~/.bashrc

Then source ~/.bashrc 这对我同样适用。

在 Windows 环境中使用“ anaconda 提示符”代替“命令提示符”。

此解决方案适用于那些不希望设置 PATH 的用户。

有时可能不需要设置 PATH。在我的例子中,我安装了 Anaconda 和另一个安装了访问 API 所需的 Python 的软件,而设置 PATH 会产生难以解决的冲突。

Under the Anaconda directory (in this case Anaconda3) there is a subdirectory called envs where all the environments are stored. When using conda activate some-environment replace some-environment with the actual directory location of the environment.

在我的例子中,命令如下所示。

conda activate C:\ProgramData\Anaconda3\envs\some-environment

I just ran into a similar issue. 最近开始在 windows 上开发,所以要习惯 PowerShell。 讽刺的是,当尝试在 Git-bash 中使用“ conda 激活”时,我得到了错误

$ conda activate obf


CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.


To initialize your shell, run


$ conda init <SHELL_NAME>


Currently supported shells are:
- bash
- cmd.exe
- fish
- tcsh
- xonsh
- zsh
- powershell


See 'conda init --help' for more information and options.


IMPORTANT: You may need to close and restart your shell after running 'conda init'.

按照指示在 PowerShell (升级)中运行命令对我来说非常有效。

conda init powershell

This should be true across all terminal environments, just strange PowerShell didn't return this error itself.

对于窗口,使用 Anaconda Powershell 提示符

enter image description here

水蟒函数在默认情况下不会导出,它可以通过使用以下命令来完成:

source ~/anaconda3/etc/profile.d/conda.sh


conda activate my_env

以下是我在窗口上使用 VS 代码中的 Git Bash 终端的简洁步骤:

  1. source activate env-name-现在您应该看到您的行后面附加了(基本)标记。

  2. 在调用 source activate之后,我发现以下 conda activate命令可以工作: 即 conda activate env2-name

对我来说,Git Bash (作为 VS 代码终端)不起作用的是: activate env-nameconda activate env-name

不完全确定为什么这种特定的行为发生在 VS 代码的 Git Bash 终端上,但是我找到的可接受的答案 + 这个 堆栈溢出问题可能会提供线索。

如果没有适合您的工作,您可以通过 conda 指定 Python 环境设置的完整路径。

对我来说,我使用 conda 设置了一个名为“ testenv”的环境。

我搜索了所有的 Python 环境

whereis python | grep 'miniconda'

它返回了一个 python 环境列表,然后我使用以下命令运行 my _ python _ file.py。

~/miniconda3/envs/testenv/bin/python3.8 my_python_file.py

You can do the same thing on windows too but looking up for python and conda python environments is a bit different.

如果在运行 conda activate base之后控制台没有显示 (base),那么尝试运行:

conda init

然后,运行 conda activate <your_env>应该在 shell 提示符的开头显示 (<your_env>)的名称。

这在 Windows 上对我很管用。我的 PATH 环境变量设置正确,所以 conda activate base没有出现任何错误,但悄悄地失败了。

在 Linux 中安装 conda 之后,如果您想创建 env,只需键入 bash 并在稍后按下 Enter 即可创建 env

只需在 cmd 中使用以下命令:

activate <envname>

非常有效! (在 windows 工作,不知道 Mac)

你试过用 Anaconda command prompt或者 Cmd吗? 它对我很有效。在 PowerShell 中没有提供错误和激活可能是一些路径问题。

从 conda 4.10.1开始,下面是我在 Windows 上使用 Sublime text 3(cmd 和 Git cmd 也是如此)中的 Git Bash 终端所做的工作:

$ source activate env_name

对我来说: $ activate env_name$ conda activate env_name没有工作!

检查激活的 Conda 环境列表,在我的情况下,我使用

$ conda env list

或者

$ conda info --envs

激活环境之前是 *

注意,我已经在路径中添加了蟒蛇。

大家好,让我分享一下对我有用的东西

  1. 将 conda 添加到 path (即环境变量-确切地说是脚本文件夹) ,即 用户 kboys anaconda3脚本
  2. 重新打开你的 cmd,键入激活和您的目标环境的名称,即

$ activate <env_name>

$ activate tensorflow

Note this way you don't need to call conda.

集合执行策略远程设计 Set-ExecutionPolicy unrestricted

我刚刚在 miniconda 中创建了一个新环境,但是当试图在 VSCode 的终端中激活它时,它给出了这个

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. If using 'conda activate' from a batch script, change your invocation to 'CALL conda.bat activate'.

然后我在 VSCode 设置中找到了这个选项,terminal.integrated.shellArgs:

Terminal options

默认情况下,它是‘ null’,但是将其更改为‘ Command Prompt’,它使得 VSCode 终端中的‘ conda active [ my env ]’命令可以工作。

我改变了我的外壳程序从 bashzsh根据苹果提示消息和重新启动终端,它为我这样做之后。

  • 在 cmd 中运行 conda init
  • 重新启动计算机辅助设计
  • 运行 conda activate envName

我也有同样的问题,但是对于 linux 来说,这个方法是有效的: 终端类型:

$ bash
$ conda init
$ cd /path_that_include_env_dir
$ conda activate ./<env_name>

或者

$ conda activate /env_path

“ env _ path”是完整的环境路径:/home/usr/env _ dir

检查环境列表及其路径 $conda env list

去设置和改变“外壳路径”到“ cmd”从电源外壳。 我在 Windows 10上使用了魅惑术,解决了我的问题。 设置 > 工具 > 终端 > shell 路径 > cmd

In my case the change of default terminal to command promt (cmd.exe) did a trick. VS Code - Windows 10

conda init

在命令提示符下运行此命令。

对我有用。