我的包結構導入包模塊是:如何從包「主」模塊
main.py mapp/ __init__.py core/ __init__.py tobeimported.py test/ __init__.py (test modules) utils/ __init__.py blasttofasta.py
文件blasttofasta.py作爲腳本執行。
blasttofasta.py樣子:
import mapp.core.tobeimported
def somefunc():
pass
if __name__ == '__main__':
pass
但出現異常:
Traceback (most recent call last):
File "utils/blasttofasta.py", line 5, in <module>
import mapp.core.tobeimported
ImportError: No module named mapp.core.analyzers
如何導入 tobeimported模塊?我運行從頂部目錄blastofofasta.py(其中main.py是)
編輯:也許更好的問題是:如何獲得mapp包到sys.path?因爲腳本文件只能看到它自己的目錄而不能看到軟件包目錄。
謝謝
python -m mapp.utils.test << This works。但我不知道它爲什麼可行,而經典的python mapp/utils/test.py沒有。 – Karlvonbahnhof