Python .pth 文件不工作
我的 .pth 配置文件中列出的目录没有出现在 sys.path 中。
配置文件的内容,名为 some_code_dirs.pth
:
/home/project
文件路径:
/usr/lib/python2.6/site-packages/some_code_dirs.pth
/usr/lib/python2.6/some_code_dirs.pth
检查 python 解释器中的 sys 变量:
>>> print sys.prefix
'/usr'
>>> print sys.exec_prefix
'/usr'
所有这些似乎都是 Python 文档,但 sys.path 不包含 /home/project 目录。
请注意,解释器确实在以下内容之后添加目录:
>>> site.addsitedir('/usr/lib/python2.6/site-packages')
我在这里缺少什么?
Directories listed in my .pth configuration file aren't appearing in sys.path.
The contents of configuration file, named some_code_dirs.pth
:
/home/project
Paths to the file:
/usr/lib/python2.6/site-packages/some_code_dirs.pth
/usr/lib/python2.6/some_code_dirs.pth
Check on sys variables in the python interpreter:
>>> print sys.prefix
'/usr'
>>> print sys.exec_prefix
'/usr'
All this seems as required in the Python documentation, but sys.path doesn't include the /home/project directory.
Note that the interpreter does add the directory after:
>>> site.addsitedir('/usr/lib/python2.6/site-packages')
What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用什么操作系统?在我的 Ubuntu 9.04 系统上,该目录不在 sys.path 中。
尝试将其放入
/usr/lib/python2.6/dist-packages
中。请注意,它是 dist 而不是 site。What OS are you using? On my Ubuntu 9.04 system that directory is not in sys.path.
Try putting it into
/usr/lib/python2.6/dist-packages
. Notice that it is dist instead of site.我有一个 类似不久前的问题。检查 pth 文件的编码。如果使用带有 BOM 的 UTF-8 编码,pth 文件似乎会被默默地忽略。
I had a similar problem a while ago. Check the encoding of your pth-file. It seems that pth-files are silently ignored if encoded in UTF-8 with BOM.