简体   繁体   English

为什么Conda在激活环境后无法调用正确的Python版本?

[英]Why Conda cannot call correct Python version after activating the environment?

I have the following conda environment under Linux:我在 Linux 下有以下 conda 环境:

$ conda info -e
# conda environments:
#
py33                     /u21/coyotito/.anaconda/envs/py33
root                  *  /u21/coyotito/.anaconda

And py33 is created with this command: py33是用这个命令创建的:

$ conda create -n py33 python=3.3 anaconda

The problem is when I activate py33 it still cannot call Python version 3.3.问题是当我激活py33它仍然无法调用 Python 3.3 版。

[coyotito@pearl ~]$ source activate py33
(coyotito)[coyotito@pearl ~]$ python --version
Python 2.7.10 :: Anaconda 2.1.0 (64-bit)
(coyotito)[coyotito@pearl ~]$ conda info -e
# conda environments:
#
py33                     /u21/coyotito/.anaconda/envs/py33
root                  *  /u21/coyotito/.anaconda

Namely it still calling old python.即它仍然调用旧python。 Notice also that the prompt under bracket is not (py33) .还要注意括号下的提示不是(py33)

(coyotito)[coyotito@pearl ~]$ which python
~/.anaconda/bin/python

Instead of python in new environment:在新环境中代替 python:

~/.anaconda/envs/py33/bin/python3.3

How can I resolve this issue?我该如何解决这个问题?

Update更新

My PATH environment in ~/.bash_profile looks like this:我在~/.bash_profile PATH 环境如下所示:

export PATH=$HOME/.anaconda/bin:$PATH

I had the exact same problem.我遇到了完全相同的问题。 Not sure what I did to get into that mess, but I solved it with a simple:不知道我做了什么让我陷入困境,但我用一个简单的方法解决了它:

conda deactivate
conda activate foo_env

(If you have activated multiple environments, you may need to run conda deactivate multiple times.) (如果您激活了多个环境,您可能需要多次运行conda deactivate activate。)

TLDR; TLDR;

# deactivate Conda environment
# (until even base environment is deactivated)
conda deactivate
# activate your environment
conda activate your_env_name_goes_here

try this试试这个

Activate an environment A and then check the location of Python package by using the command below.激活环境 A,然后使用以下命令检查 Python 包的位置。

python -c "import sys; print(sys.executable)" python -c "import sys; print(sys.executable)"

Activate another environment, let's say environment B and rerun the above python command.激活另一个环境,假设环境 B 并重新运行上面的 python 命令。 If conda isn't using the correct Python version then most likely running the above command will print the same path in both environments.如果 conda 未使用正确的 Python 版本,则很可能运行上述命令将在两种环境中打印相同的路径。

My conda installation wasn't using the correct version because I had activated my environment on top of the conda base environment.我的 conda 安装没有使用正确的版本,因为我在 conda 基础环境之上激活了我的环境。

Deactivating the base environment and then activating the environment I wanted, worked.停用基础环境,然后激活我想要的环境,工作。

Landed here with this same issue, but by moving out of the anaconda executable directory, the correct python was called.在这里遇到了同样的问题,但是通过移出 anaconda 可执行目录,调用了正确的 python。 I was in a directory that contained the python executable that was installed with Anaconda2.我在一个包含与 Anaconda2 一起安装的 python 可执行文件的目录中。

Example:示例:

(py35) C:\Anaconda>python --version
Python 2.7.11 :: Anaconda 4.0.0 (64-bit)

(py35) C:\Anaconda>cd ..

(py35) C:\>python --version
Python 3.5.2 :: Anaconda 4.2.0 (64-bit)

(py35) C:\>

因此,在我的情况下,我之前的实习生将 anaconda 路径附加到/etc/profile路径变量,这会覆盖~/.bashrc conda 设置,只需删除/etc/profile那些行即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM