【发布时间】:2011-07-08 20:52:20
【问题描述】:
我有几个 Python 项目,它们都有一个 conf 包:
/some_folder/project_1/
conf/
__init__.py
some_source_file.py
/another_folder/project_2/
conf/
__init__.py
another_source_file.py
对于每个项目,我在 site-packages 文件夹中创建了一个 .pth 文件,其中包含以下内容:
.../site-packages/project_1.pth:
import sys; sys.path.append('/some_folder/project_1/')
.../site-packages/project_2.pth:
import sys; sys.path.append('/another_folder/project_2/')
我可以访问/some_folder/project_1/中的模块:
import conf.some_source_file
但不是/another_folder/project_2/中的模块:
import conf.another_source_file
AttributeError: 'module' object has no attribute 'another_source_file'
看起来好像python只搜索sys.path中任何文件夹下的第一个conf路径。有办法解决吗?
【问题讨论】: