gpt4 book ai didi

PYTHONPATH 被忽略

转载 作者:太空狗 更新时间:2023-10-29 18:22:36 25 4
gpt4 key购买 nike

环境:debian 4.0

python 2.4

我的“项目”安装在:

/usr/lib/python2.4/site-packages/project.

但我想使用我的工作副本而不是位于以下位置的已安装副本:

/home/me/dev/project/src

所以我做的是:

export PYTHONPATH=/home/me/dev/project/src

ipython

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

怎么会?我尝试检查路径(完成上面的导出),我看到的是:

import sys,os

sys.path

['', '/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']

/home/me/dev/project/src

最佳答案

根据 python 文档,这是预期的行为:https://docs.python.org/2.4/lib/module-sys.html :

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

关于PYTHONPATH 被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1001851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com