英文:
Numpy incompatibility with cx_freeze
问题
我正在制作一个可以使用cx_Freeze执行的程序。这个程序使用了几个库,比如matplotlib和scipy。
当我使用我的“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文件一样?
英文:
I'm in the process of making a program executable with cx_Freeze. This program uses several libraries such as matplotlib and scipy.
When I create my executable with my "setup.py", I get this error:
RecursionError: maximum recursion depth exceeded during compilation
I then ran several tests to find out which library was causing the problem, and it was numpy.
When I exclude numpy from my setup.py, the executable file is created, but when I run it, I get an error telling me that numpy has not been imported, since matplotlib and scipy use it.
Here's my 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")],
)
I'm trying to import manually numpy but i don't know how. Is there a way to increase the number of possible recursions, like with pyinstaller and .spec ?
答案1
得分: 0
好的,这是翻译好的部分:
好的,我刚刚找到了解决办法。
我尝试增加可能递归的次数,就像pyinstaller的.spec一样。通过在我的“setup.py”文件中添加完全相同的代码行,我可以创建我的可执行文件,而且不再有任何兼容性问题。
这是我的可工作代码:
导入sys
从cx_Freeze导入设置,可执行文件
# 依赖项会自动检测,但可能需要微调。
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" 仅适用于Windows GUI应用程序
base = "Win32GUI" if sys.platform == "win32" else None
安装(
名称="应用程序",
版本="0.1",
描述="软件",
选项={"build_exe": build_exe_options},
可执行文件=[Executable("main.py", base=base, icon="icon.ico")],
)
英文:
Well, I've just found the solution to my problem.
I've tried increasing the number of possible recursions as with pyinstaller's .spec. By adding exactly the same line of code in my "setup.py" file, I can have my executable created and I no longer have any compatibility problems.
Here's my working code :
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")],
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论