我创建了一个小脚本来测试cx_Freeze,如下所示:
sqrt.py:
import math sqrt = math.sqrt x = float(input('Enter a number:')) y = sqrt(x) print(y) input('Press ENTER to exit')
我还创建了一个安装脚本:
setup.py:
from cx_Freeze import setup,Executable setup( name = "sqrt",version = "0.1",description = "Testing",# options = {"build_exe": build_exe_options},executables = [Executable("sqrt.py")])
接下来,我在python.exe,sqrt.py和setup.py所在的文件夹中启动Windows cmd.exe,然后输入:
path\python.exe setup.py build
应该这样,这会创建一个构建目录,其中包含sqrt.exe.当我尝试执行它时,它返回
“The application was unable to start correctly (0xc000007b). Click OK
to close the application.”
据我了解cx_Freeze文档,这应该工作.同样适用于我观看过的各种YouTube教程.
我正在运行Windows10 64x,Python 3.5和cx_freeze 5.0.
解决方法
您可以使用
dependencywalker加载使用cx_freeze创建的exe文件.
它会告诉你什么是错的.
也许你错过了像Microsoft Visual C++ Redistributable Package这样的库,或者你混合了32位和64位架构.
更新:当我尝试在Windows上运行gtk时,我遇到了这个问题.有什么奇怪的事情.我从gtk切换到pyside2(QT),现在事情变得容易了.