PYTHONPATH 被忽略
问题描述
环境:debian 4.0
Environment: debian 4.0
Python 2.4
我的项目"安装在:
/usr/lib/python2.4/site-packages/project.
/usr/lib/python2.4/site-packages/project.
但我想使用我的工作副本,而不是位于以下位置的已安装副本:
But I want to use my working copy instead of the installed one which is located in:
/home/me/dev/project/src
/home/me/dev/project/src
所以我要做的是:
导出 PYTHONPATH=/home/me/dev/project/src
export PYTHONPATH=/home/me/dev/project/src
ipython
import foo # 在 src 中
import foo # which is in src
foo.__file__
*/usr/lib/python2.4/site-packages/project/foo.py*
而不是:
/home/me/dev/project/src/project/foo.py
/home/me/dev/project/src/project/foo.py
怎么会?我尝试检查路径(已完成上面的导出),我看到的是:
How come? I try to check the pathes (having done the export above) and what I see is:
导入系统,操作系统
系统路径
['','/usr/bin','/usr/lib/python2.4/site-packages','/home/me/dev/project/src','/usr/lib/python24.zip','/usr/lib/python2.4','/usr/lib/python2.4/plat-linux2','/usr/lib/python2.4/lib-tk','/usr/lib/python2.4/lib-dynload','/usr/local/lib/python2.4/site-packages','/usr/lib/python2.4/site-packages/PIL','/var/lib/python-support/python2.4','/usr/lib/python2.4/site-packages/IPython/Extensions','/home/me/.ipython']
os.environ['PYTHONPATH']
os.environ['PYTHONPATH']
/home/me/dev/project/src
解决方案
根据 python 文档,这是预期行为:https://docs.python.org/2.4/lib/module-sys.html:
According to python documentation, this is expected behavior: https://docs.python.org/2.4/lib/module-sys.html:
注意脚本目录是在插入的条目之前插入作为 PYTHONPATH 的结果.
Notice that the script directory is inserted before the entries inserted as a result of PYTHONPATH.
在 python-2.6 下是不同的:http:///docs.python.org/tutorial/modules.html#the-module-search-path
Under python-2.6 it is different: http://docs.python.org/tutorial/modules.html#the-module-search-path
相关文章