cx-freeze“导入错误:DLL加载失败:%1不是有效的Win32应用程序”]]

问题描述 投票:1回答:1

我安装了用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

我安装了带有pip3(所有64位)的PyQt5.5.13.2,并且我很确定我安装了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

为什么?

AND ... cx-freeze脚本使用sys.platform决定要使用的库,因此它选择

base=Win32GUI

我该怎么办?

[我注意到python setup.py build用完了cmd shell,无论我怎么打开,它总是32位;甚至PowerShell是32位。这可能是问题吗?

我安装了用cx-freeze冻结的python / pyqt / matplotlib应用程序后出现错误。我用python setup.py构建应用程序。build setup.py是来自cx_Freeze导入设置,...

python numpy matplotlib pyqt cx-freeze
1个回答
0
投票

在90%的情况下,此错误是64位和32位混合的结果。假设这里的所有测试都是准确的,我猜您正在使用的开发机具有64位的所有功能,但是其他Windows计算机要么具有为32位设计的DLL,要么Windows系统本身是32位安装(甚至如果机器本身是64位)。

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

© www.soinside.com 2019 - 2024. All rights reserved.