2017-07-27 55 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