CX冷冻"ImportError: DLL load failed: %1 is not a valid Win32 application"



安装使用 cx-freeze 冻结的 python/pyqt/matplotlib 应用程序后,我收到错误。 我构建应用程序

python setup.py build

这是 setup.py

from cx_Freeze import setup, Executable
buildOptions = dict(packages = [], excludes = [])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('SectionPropertyCalculator.py', base=base)
]
setup(name='Mecanica-SectionPropertyCalculator',
version = '0.1',
description = 'SPC is a GUI to calculate geometrical properties of beam profiles.',
options = dict(build_exe = buildOptions),
executables = executables)

我得到

Mecanica-SectionPropertyCalculator-0.1-amd64.exe 

.exe在我的开发计算机上运行正常

然后我创建一个 msi 安装程序

cx-freeze app bdist_msi

我得到

Mecanica-SectionPropertyCalculator-0.1-amd64.msi 

我将其安装到另一台具有相同操作系统、i5 处理器等的机器上,但出现错误

File "C:...SpcPlotQt.py", line 4 in <module> 
ImportError: DLL load failed: %1 is not a valid Win32 application

现在,SpcPlotQt.py 是我的代码,在第 4 行我有

from PyQt5.QtWidgets import QDialog, QApplication

我安装了 PyQt5.5.13.2 和 pip3(所有 64 位(,我很确定我安装了 python 3.7 x64,我确认

import struct; print( 8 * struct.calcsize("P"))
64

另外,如果我运行

import sys; print("%x" % sys.maxsize, sys.maxsize > 2**32)
True

import ctypes; print (ctypes.sizeof(ctypes.c_voidp))
8

import platform; platform.architecture()[0]
64bit

import os; os.environ["PROCESSOR_ARCHITECTURE"]
AMD64

上面的所有 5 个测试都表明一切都是 64 位的。

但是当我跑步时

import sys; print (sys.platform)
win32

为什么?

而且...cx-freeze脚本使用sys.platform来决定使用什么基础,因此它选择。

base=Win32GUI

我该怎么办?

我注意到python setup.py build用完了cmd shell,无论我如何打开它,它总是32位;即使是PowerShell也是32位。这可能是问题所在吗?

在 90% 的情况下,此错误是 64 位和 32 位混合的结果。假设您在这里的所有测试都是准确的,我猜您使用的开发机器的所有内容都是 64 位,但另一台 Windows 机器要么具有指定为 32 位的 DLL,要么 Windows 系统本身是 32 位安装(即使机器本身是 64 位(。

不用担心sys.platform返回win32,这就是它的作用。

在两台计算机上尝试基础知识:右键单击文件资源管理器中的computer,然后properties- 查看Windows的安装是32位还是64位。如果另一台机器是 32 位的,则您的 exe 与它不兼容,除非您愿意更改操作系统。

另一种解决方案:在您的开发计算机上安装 python 32 位版本,使用它制作 exe 文件几乎可以保证它可以在 32 位和 64 位系统上工作。

相关内容

最新更新