Python py2exe的相对导入错误

Python py2exe的相对导入错误,python,py2exe,relative-import,Python,Py2exe,Relative Import,我试图为一个简单的Python脚本生成一个可执行文件。我的setup.py代码如下所示: from distutils.core import setup import py2exe setup(console=["script.py"]) 但是,我得到了屏幕截图中显示的错误。有什么我可以试着解决的吗?我正在使用Windows10 在你的mf3.py中,你似乎是 假设您的项目结构如下: folder/ main.py mod/ __init__.py components/

我试图为一个简单的Python脚本生成一个可执行文件。我的setup.py代码如下所示:

from distutils.core import setup
import py2exe
setup(console=["script.py"])
但是,我得到了屏幕截图中显示的错误。有什么我可以试着解决的吗?我正在使用Windows10


在你的mf3.py中,你似乎是

假设您的项目结构如下:

folder/
main.py
mod/
    __init__.py
    components/
        __init__.py
        expander.py
        language_id.py
    utilities/
        __init__.py
        functions.py
首先确保

main.py将子包称为:

expander.py和language_id.py可以通过以下方式访问functions.py:

from..utilities.functions import*

向设置中添加选项。py

为了导入项目所需的所有模块和包,还可以使用更多。例如

# setup.py
from distutils.core import setup
import py2exe
setup(console=["script.py"],
      options={
              "py2exe":{
                    "optimize": 2,
                    "includes": ["mf1.py", "mf2.py", "mf3.py"], # List of all the modules you want to import
                    "packages": ["package1"] # List of the package you want to make sure that will be imported
               }
       }
    )

通过这种方式,您可以强制导入缺少的项目脚本

需要更多信息,例如,您的项目文件结构。但是尝试将py2exe路径添加到PYTHONPATH中?
# setup.py
from distutils.core import setup
import py2exe
setup(console=["script.py"],
      options={
              "py2exe":{
                    "optimize": 2,
                    "includes": ["mf1.py", "mf2.py", "mf3.py"], # List of all the modules you want to import
                    "packages": ["package1"] # List of the package you want to make sure that will be imported
               }
       }
    )