Python 向 PATH 添加了很多东西。我该如何停止?

标签 python python-3.x

我发现 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 (pythonipython)启动 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 to sys.path.

关于Python 向 PATH 添加了很多东西。我该如何停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32670985/

相关文章:

java - Python 套接字从 Java PrintWriter 套接字接收不完整的消息

python - 将不平衡学习与 Pandas DataFrame 结合使用

python - 使用 Python 2.7 在出现字符串的位置拆分文本文件

java - 如何通过 Java 客户端和 Python 服务器通过套接字创建 IPC?

python - Ubuntu 升级后无法将 chromedriver 与 Selenium 一起使用

Python 一行 if 语句有两个 Action

python - 为什么在调用函数时需要将函数分配给标识符?

python - 如何在 scrapy 中避免错误 "TypeError: a bytes-like object is required, not ' str'"

Python字符生成

python - QTableWidget 动态行 w/QComboBox