Numpy与cx_freeze不兼容

q8l4jmvw  于 2023-06-23  发布在  其他
关注(0)|答案(1)|浏览(117)

我正在用cx_Freeze编写一个可执行程序。这个程序使用了几个库,如matplotlib和scipy。当我用我的“www.example.com”创建可执行文件时setup.py,我得到这个错误:RecursionError: maximum recursion depth exceeded during compilation然后我运行了几个测试来找出哪个库导致了这个问题,结果是numpy。当我从setup.py中排除numpy时,创建了可执行文件,但当我运行它时,我得到一个错误,告诉我numpy尚未导入,因为matplotlib和scipy使用它。下面是我的setup.py:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
    "includes": ["tkinter", "matplotlib", "pyvisa", "PIL", "cmath", "sympy", "scipy"],
    # "excludes": ["numpy"],    
    "zip_include_packages": ["encodings", "PySide6", "numpy"],
}

# base="Win32GUI" should be used only for Windows GUI app
base = "Win32GUI" if sys.platform == "win32" else None

setup(
    name="App",
    version="0.1",
    description="Software",
    options={"build_exe": build_exe_options},
    executables=[Executable("main.py", base=base, icon="icon.ico")],
)

我尝试手动导入numpy,但我不知道如何。有没有办法增加可能的递归的数量,比如pyinstaller和.spec?

y53ybaqx

y53ybaqx1#

我刚刚找到了解决问题的办法。我尝试增加可能的递归数,就像使用pyinstaller的.spec.通过在“www.example.com”文件中添加完全相同的代码行setup.py,我可以创建我的可执行文件,并且我不再有任何兼容性问题。下面是我的工作代码:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
    "includes": ["tkinter", "matplotlib", "pyvisa", "PIL", "cmath", "sympy", "scipy", "numpy"],
    "zip_include_packages": ["encodings", "PySide6", "numpy"],
}

sys.setrecursionlimit(sys.getrecursionlimit() * 5)

# base="Win32GUI" should be used only for Windows GUI app
base = "Win32GUI" if sys.platform == "win32" else None

setup(
    name="App",
    version="0.1",
    description="Software",
    options={"build_exe": build_exe_options},
    executables=[Executable("main.py", base=base, icon="icon.ico")],
)

相关问题