2017-07-27 56 views
0

我有這樣的目錄結構:導入包沒有sys.path中

proj/ 
|- src/ 
    |- org/ 
    |- example/ 
     |- dir/ 
     |- foo.py 
     |- ... 
|- src2/ 
    |- org/ 
    |- example/ 
     |- dir/ 
     |- bar.py 
     |- ... 

我的問題是:如何導入foobar不使用sys.path,如果可能,避免寫一個__init__.py文件在每個子目錄src?請注意,實際的.py文件只有在相關時才位於dir文件夾中。

回答

0

from src.org.example.dir import foo

+0

這就提出了一個'ModuleNotFoundError:無模塊命名爲「src''。 – norb