import sys
print(sys.path)
'C:\\python32\\Lib\\site-packages\\django'
'C:\\Python32'
'C:\\Python32\\lib\\site-packages'
...
由于某种原因,我的 pythonpath 变得困惑。我想组织一下。我不需要上面的第一个和最后一个,对吗?我怎样才能永久改变它? (不像 sys.path.remove 或 sys.path.append)
我使用的是Python3.2。在Windows8中。
最佳答案
路径“C:\Python32\lib\site-packages”通过内置 site 添加到 sys.path模块。
如果您愿意,可以使用 -S 标志启动 python 来告诉站点模块“不要添加站点包”。
python -S
接下来,'C:\python32\Lib\site-packages\django'。
这是一个疯狂的猜测:您使用 pip/easy_install/msi-installer 安装了 django 并且有一个文件
C:\python32\Lib\site-packages\django.pth (或类似以 .pth 结尾的内容)
引用文档:
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.
您可以删除 django.pth 文件(不推荐,见下文)以从 sys.path 中删除“..../django”
所以,简短的回答:不要弄乱 sys.path,sys.path 中的内容可能是有充分理由的。 如果您不需要 django,请使用您用来安装 django 的任何工具卸载 django。对于您不需要的每个包都相同。
关于python - 如何永久编辑(删除)sys.path?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27910483/