Reputation: 204
I am getting an error after I install a python/pyqt/matplotlib app that I freeze with cx-freeze. I build the app with
python setup.py build
setup.py is this
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)
I get
Mecanica-SectionPropertyCalculator-0.1-amd64.exe
The .exe runs ok on my dev machine
Then I create a msi installer with
cx-freeze app bdist_msi
I get
Mecanica-SectionPropertyCalculator-0.1-amd64.msi
I install it into another machine with same OS, i5 processor, etc. and I get an error
File "C:\...SpcPlotQt.py", line 4 in <module>
ImportError: DLL load failed: %1 is not a valid Win32 application
Now, SpcPlotQt.py is my code and on line 4 I have
from PyQt5.QtWidgets import QDialog, QApplication
I have PyQt5.5.13.2 installed with pip3 (everything 64 bit) and I am pretty sure I installed python 3.7 x64, which I confirm by
import struct; print( 8 * struct.calcsize("P"))
64
Also, if I run
import sys; print("%x" % sys.maxsize, sys.maxsize > 2**32)
True
and
import ctypes; print (ctypes.sizeof(ctypes.c_voidp))
8
and
import platform; platform.architecture()[0]
64bit
and
import os; os.environ["PROCESSOR_ARCHITECTURE"]
AMD64
All 5 tests above tells that everything is 64 bit.
But when I run
import sys; print (sys.platform)
win32
Why?
AND... cx-freeze scripts use sys.platform to decide what base to use, thus it chooses
base=Win32GUI
What should I do?
I notice that python setup.py build
runs out of a cmd shell, which is always 32 bit, no matter how I open it; even a PowerShell is 32 bit. Could this be the problem?
Upvotes: 1
Views: 591
Reputation: 11922
In 90% of cases this error is the result of some mixing of 64bit and 32bit. Assuming all your tests here are accurate, I'm guessing the dev machine you are using has everything at 64bit, but the other windows machine either has a DLL that was desinged for 32 bit, or the windows system itself is a 32bit installation (even if the machine itself is 64 bit).
Don't worry about sys.platform
returning win32
, that's what it does.
Try the basics on both machines: right click on computer
in the file explorer and then properties
- see if the installation of windows is 32 or 64 bit. If the other machine is 32 bit, then your exe isn't compatible with it unless you're willing to change the OS.
An alternative solution: install the python 32 bit version on your dev machine, making the exe file with it pretty much guarantees that it will work on both 32 and 64 bit system.
Upvotes: 1