我发现 python 正在以有问题的方式修改我的路径——特别是,它预先设置了我的 github 开发文件夹的路径,这导致加载了错误的库。
在我的终端 session 中,如果我运行 echo $PATH
我得到:
~$echo $PATH
/Users/Nick/anaconda/bin:/usr/local/bin:/usr/bin:
/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/texbin
这是完美的。但是当我从同一个终端 session (python
或 ipython
)启动 python 并从 python 中检查我的 PATH 时,我得到:
>>> print(sys.path)
['', '/Users/Nick/anaconda/lib/python3.4/site-packages/Cython-0.22.1-py3.4-
macosx-10.5-x86_64.egg', '/Users/Nick/github/pandas',
'/Users/Nick/anaconda/lib/python34.zip', '/Users/Nick/anaconda/lib/python3.4',
'/Users/Nick/anaconda/lib/python3.4/plat-darwin',
'/Users/Nick/anaconda/lib/python3.4/lib-dynload',
'/Users/Nick/anaconda/lib/python3.4/site-packages',
'/Users/Nick/anaconda/lib/python3.4/site-packages/Sphinx-1.3.1-py3.4.egg',
'/Users/Nick/anaconda/lib/python3.4/site-packages/aeosa',
'/Users/Nick/anaconda/lib/python3.4/site-packages/setuptools-18.0.1-py3.4.egg']
这些来自哪里?我该如何阻止它们?
谢谢!
最佳答案
PATH
与Python模块搜索路径无关;您的 shell 使用该环境变量来查找可执行文件。
您需要查看 PYTHONPATH
variable在这里。
如果该变量不包含您的额外元素,请使用 -S
command line switch 启动 Python禁用加载 site.py
;额外的元素可能是由 .pth
文件设置的。另见 site
module documentation :
A path configuration file is a file whose name has the form
name.pth
and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added tosys.path
.
关于Python 向 PATH 添加了很多东西。我该如何停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32670985/