M
M
malls2015-06-17 20:13:58
Software Deployment
malls, 2015-06-17 20:13:58

How to fix errors when running python script file.py converted to file.exe?

Good evening.
It was necessary to get a program that would work under xp and under win7. There are 4 buttons and 4 labels, a call to an external utility using subprocess.call, as arguments - the path to the selected files / folders. Wrote it in PyQt, googled tutorials on how to convert .py to .exe, got an exe file with py2exe, but it only works on my machine. Tried with pyinstaller, same thing.
On others, it either does not start or gives an error
This application failed to start because it could not find or load the Qt platform plugin "windows"
Reinstalling the application may fix this problem
Added the C:\Python34\Lib\site-packages\PyQt4\plugins folder \platforms to the folder with the resulting exe (there are qwindows.dll and qminimal.dll) - another line appears
Available platform plugins are: minimal, windows.
For py2exe in notepad++ I created such a script, saved it in utf-8 without BOM
from distutils.core import setup
import py2exe
setup(
windows=[{"script":"convert.py"}],
options={"py2exe": {" includes":["sip","PyQt4._qt"]}}
)
or instead of "PyQt4._qt" added "PyQt4.QtGui" "PyQt4.Core"
after running the command "python script.py py2exe"
a message appears about 3 missing modules
? readline imported from cmd, code,
pdb ? win32api imported from platform
? win32con imported from platform
tried in setup.py from platform import * or "includes":["sip","platform"]
With Pyinstaller:
Pyinstaller pyinstaller --onedir --onefile --windowed "C:\Python34\convert.py"
Result - on mine it starts, on others the same error.
I installed python3.4.3 on another computer, PyQt4-4.11.4-gpl-Py3.4-Qt5.4.2-x32 added all the paths to Path, the same error.
I tried to put my exe with dlls in a folder with another program written in PyQt, and its dlls - it didn’t work,
the same error.
Details of the computer on which I wrote:
CPU type TripleCore AMD Athlon II X3 445, 3100 MHz (15.5 x 200) Motherboard
Asus M5A78L-M LX
Motherboard chipset AMD 760G, AMD K10
System memory 1792 MB (DDR3-1333 DDR3 SDRAM) Installed : OS
:
Windows 7 x64 Service Pack 1
all win 7 updates -Py3.4-Qt5.4.2-x32 py2exe-0.9.2.0 x86 pywin32-219.win32-py3.4 Tested on computers with Windows 7 x64 and Windows xp Service Pack 3 Everything was added to the Path system variable C:\Python34 ;C:\Python34\Scripts;C:\Python34\Lib\site-packages\PyQt4 advised to add QT_QPA_PLATFORM_PLUGIN_PATH variable C:\Python34\Lib\site-packages\PyQt4\plugins\platforms added this path both in Path - not helped

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2015-06-18
@Avernial

Good afternoon.
Try building with py2exe like this:
Main.py file:

from PyQt4.QtCore import *
from PyQt4 import QtGui
 
class HelloPython(QtGui.QWidget):
    def __init__(self, parent=None):
        super(HelloPython, self).__init__(parent)
        helloLabel = QtGui.QLabel("Say Hello To PyQT!")       
        helloLineEdit = QtGui.QLineEdit()
 
        mainLayout = QtGui.QGridLayout()
        mainLayout.addWidget(helloLabel, 0, 0)
        mainLayout.addWidget(helloLineEdit, 0, 1)
 
        self.setLayout(mainLayout)
        self.setWindowTitle("My Python App")
 
if __name__ == '__main__':
    import sys
 
    app = QtGui.QApplication(sys.argv)
 
    helloPythonWidget = HelloPython()
    helloPythonWidget.show()
 
    sys.exit(app.exec_())

setup.py file:
from distutils.core import setup
import py2exe

setup(windows=['main.py'], options={"py2exe": {"bundle_files": 1, "compressed": True, "includes": ["sip"]}})

Checked on Windows 7-x64 and Windows XP-x64.
python-3.4 installed from the official site.
py2exe‑0.9.2.2‑cp34‑none‑win_amd64.whl and PyQt4‑4.11.4‑cp34‑none‑win_amd64.whl from the Python Extension site .
It looks like you have packages for different platforms. For example, if python is for x86 and py2exe is for x64.

I
Ivan, 2015-06-17
@LiguidCool

Download AutoIT and don't fool around. Will work on almost any machine with Win 2000 and above. Unless, of course, the goal is not the result, but just to make a fool of yourself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question