我有幾個Python項目,他們都有一個CONF包:具有相同名稱的進口Python模塊
/some_folder/project_1/
conf/
__init__.py
some_source_file.py
/another_folder/project_2/
conf/
__init__.py
another_source_file.py
對於每一個項目,我已經創建的站點包文件夾中的文件.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'
它看起來彷彿蟒蛇只搜索在sys.path
任何文件夾下的第一個conf
路徑。有沒有辦法解決這個問題?
可能重複的[Python:導入具有相同名稱的不同模塊](http://stackoverflow.com/questions/32884206/python-importing-different-module-with-same-name) – luator