`anaconda` 是否为每个新环境创建一个单独的 PYTHONPATH 变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17386880/
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
Does `anaconda` create a separate PYTHONPATH variable for each new environment?
提问by krishnab
I am starting to work with the Python Anaconda distribution from Continuum.io to do scipy
work.
I have been able to get Anaconda up and running, but I cannot tell whether Anaconda creates a new PYTHONPATH
environment variable for each new environment it creates, or whether it relies on the common system PYTHONPATH
.
我开始使用 Continuum.io 的 Python Anaconda 发行版来完成scipy
工作。
我已经能够启动并运行 Anaconda,但我无法确定 Anaconda 是否为它创建的每个新环境创建了一个新的PYTHONPATH
环境变量,或者它是否依赖于公共系统。 PYTHONPATH
I could not find any information on this in the documentation.
我在文档中找不到任何关于此的信息。
Further, when I did a printenv
, I did not see a PYTHONPATH
variable in the newly created environment --though I did find a few new anaconda created environment variables.
此外,当我执行 a 时printenv
,我没有PYTHONPATH
在新创建的环境中看到变量——尽管我确实找到了一些新的 anaconda 创建的环境变量。
The best I can find is that Anaconda added some Anaconda directories and the new environment directory to the head of PATH
variable --but this does not necessarily isolate the new package from the system environment but it is close.
我能找到的最好的是 Anaconda 在PATH
变量的头部添加了一些 Anaconda 目录和新的环境目录——但这不一定将新包与系统环境隔离,但它很接近。
Does anyone know the answer to this question or found a way to deal with this concern?
有没有人知道这个问题的答案或找到解决这个问题的方法?
采纳答案by asmeurer
No, the only thing that needs to be modified for an Anaconda environment is the PATH (so that it gets the right Python from the environment bin/
directory, or Scripts\
on Windows).
不,Anaconda 环境唯一需要修改的是 PATH(以便它从环境bin/
目录或Scripts\
Windows 中获取正确的 Python )。
The way Anaconda environments work is that they hard link everything that is installed into the environment. For all intents and purposes, this means that each environment is a completely separate installation of Python and all the packages. By using hard links, this is done efficiently. Thus, there's no need to mess with PYTHONPATH because the Python binary in the environment already searches the site-packages in the environment, and the lib of the environment, and so on.
Anaconda 环境的工作方式是它们硬链接安装到环境中的所有内容。出于所有意图和目的,这意味着每个环境都是 Python 和所有包的完全独立的安装。通过使用硬链接,这可以有效地完成。因此,没有必要弄乱 PYTHONPATH,因为环境中的 Python 二进制文件已经搜索了环境中的站点包,以及环境的库,等等。
回答by inodb
Anaconda does not use the PYTHONPATH
. One should however note that if the PYTHONPATH
is set it could be used to load a library that is not in the anaconda environment. That is why before activating an environment it might be good to do a
Anaconda 不使用PYTHONPATH
. 但是应该注意,如果PYTHONPATH
设置了它,它可以用于加载不在 anaconda 环境中的库。这就是为什么在激活环境之前最好做一个
unset PYTHONPATH
For instance this PYTHONPATH points to an incorrect pandas lib:
例如,这个 PYTHONPATH 指向一个不正确的熊猫库:
export PYTHONPATH=/home/john/share/usr/anaconda/lib/python
source activate anaconda-2.7
python
>>>> import pandas as pd
/home/john/share/usr/lib/python/pandas-0.12.0-py2.7-linux-x86_64.egg/pandas/hashtable.so: undefined symbol: PyUnicodeUCS2_DecodeUTF8
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/john/share/usr/lib/python/pandas-0.12.0-py2.7-linux-x86_64.egg/pandas/__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
ImportError: /home/john/share/usr/lib/python/pandas-0.12.0-py2.7-linux-x86_64.egg/pandas/hashtable.so: undefined symbol: PyUnicodeUCS2_DecodeUTF8
unsetting the PYTHONPATH
prevents the wrong pandas lib from being loaded:
取消设置PYTHONPATH
可防止加载错误的熊猫库:
unset PYTHONPATH
source activate anaconda-2.7
python
>>>> import pandas as pd
>>>>