這是目錄佈局子模塊的合併:如何使第二個模塊對python解釋器可見?
❯ tree
.
├── src1
│ └── some
│ ├── __init__.py
│ ├── __init__.pyc
│ └── fish
│ ├── __init__.py
│ └── __init__.pyc
└── src2
└── some
├── __init__.py
├── __init__.pyc
└── bird
├── __init__.py
└── __init__.pyc
我希望能導入some.fish
和some.bird
模塊。
如果我設置環境變量PYTHONPATH
這樣:
❯ export PYTHONPATH=./src1:./src2
❯ python
Python 2.7.9 (default, Dec 30 2014, 18:28:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import some.fish
>>> import some.bird
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bird
>>>
這是不可能的,以使bird
模塊some
下出現?
的解決方案,我想避免:
1)改變目錄結構
2)更改父包some
在其他字的名字,我可以合併在兩個子模塊沒有將文件放在同一個目錄結構下的相同模塊名稱?
是否有一個原因,包裝在兩個SRC1和SRC2有同名「some」? – skyline75489