Python:从子目录导入(子文件夹中的引用)

时间:2017-08-25 09:01:00

标签: python import module package subdirectory

我有一个文件

`XYZ\Application.py`

包含多个Python文件的包,例如

XYZ\Python\UserInterface.py 

Application.py 内部我只是使用 UserInterface ,所以我用

导入它
 from Python.UserInterface import UserInterface 

(Python文件夹包含__init__.py(如果这甚至很重要))。但UserInterface再次使用许多不同的文件/模块,这些文件/模块存储在同一目录中并由UserInterace导入。但是,如果我只是说from Reader import Reader,我会收到ModuleNotFoundError: No module named 'Reader'错误。我是否真的需要使用Python.whatever引用包内的每个导入?

1 个答案:

答案 0 :(得分:0)

你有没有尝试过:

from .Reader import Reader

from Python.Reader import Reader
UserInterface.py

中的