文件夹中的模块 __init__.py 无法导入该文件夹中的模块

A module __init__.py from a folder cannot import the modules in that folder

使用 python 3. 我正在尝试使用 wxpython 模块 "aui"

我将 aui 文件夹从 wxPython-src-3.0.2.0\wxPython\wx\lib\agw\aui 复制到我的项目目录中

例如:

/aui (Folder)

    __init__.py 
    aui_constants.py
    aui_switcherdialog.py
    ...
    ...
    tabmdi.py

myfile.py

在myfile.py中,我简单地试了一下

import aui 

__init__.py 依次尝试:

from aui_constants import *
from aui_utilities import *
from auibar import *    

...但即使它们与 __init__.py

在同一文件夹中也会引发导入错误
from aui_constants import *
ImportError: No module named 'aui_constants'

您需要使用相对导入

您可以使用 from .aui_constants import * 进行导入,对于其他导入语句也是如此。