Pyinstaller Packaging PYQT Files

Source: Internet
Author: User

How to generate EXE binaries for PYQT, Pyinstaller is such a tool

You can convert a script file. py file to an edited binary after you publish it

Next, if you pack

One. Installation:

: Https://github.com/pyinstaller/pyinstaller

Latest Version pyinstaller2.1.1 (2015-01)

Python setup.py Install

Pyinstaller is a dependent package, you must install PYWIN32 before installation, find the corresponding version of Pywin32.msi on the Internet

Two. Write a py file to package

#-*-coding:utf-8-*-ImportSYS fromPyQt4ImportQtgui, QtcoreclassButtonredrect (qtgui.qwidget):def __init__(self): Super (Buttonredrect, self).__init__() Self.setwindowtitle ('Mouse Event') Self.setwindowicon (Qtgui.qicon ('Qq.png')) Self.labels= Qtgui.qlabel (U'I'll try it! ', self) self.labels.setGeometry (50, 50, 150, 50) Self.labels.mouseReleaseEvent=self.eventsdefEvents (self, event): EV=Event.button ()ifev==QtCore.Qt.LeftButton:OK= QtGui.QMessageBox.information (Self, (U'Tips'), (U'left button'), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)ifok==QtGui.QMessageBox.Yes:QtGui.QMessageBox.information (Self, (U'Tips'), (U'YES'), QtGui.QMessageBox.Yes)Else: QtGui.QMessageBox.information (Self, (U'Tips'), (U'NO'), QtGui.QMessageBox.Yes)elifEV = =QtCore.Qt.RightButton:OK= QtGui.QMessageBox.warning (Self, (U'Tips'), (U'Right-click'), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)elifEV = =QtCore.Qt.MiddleButton:OK= QtGui.QMessageBox.question (Self, (U'Tips'), (U'Scroll Axis'), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) app=qtgui.qapplication (SYS.ARGV) Buttonr=Buttonredrect () buttonr.show () Sys.exit (App.exec_ ())

Three. File packaging

Under the sibling directory you want to package, create a new pyinstaller.py with the following content

#!/usr/bin/env python#-----------------------------------------------------------------------------#Copyright (c), Pyinstaller development Team.##distributed under the terms of the GNU general public License with exception#For distributing bootloader.##the full license are in the file COPYING.txt, distributed with this software.#-----------------------------------------------------------------------------"""Main command-line interface to Pyinstaller."""#From pyinstaller Import *ImportOSif __name__=='__main__':     fromPyinstaller.mainImportRun opts=['abc.py','- F','- W','--icon=favicon.ico'] Run (opts)

Where opts is the parameter, change the parameter to the requirement you want

--Parameter Description:

-F,--onefile PY Code has only one file

-D,--onedir py code in a directory (this is the default)

-K,--TK contains TCL/TK

-D,--debug generate EXE file for debug mode

-W,--windowed,--noconsole form exe file (Windows only)

-C,--nowindowed,--console console exe file (Windows only)

-O DIR,--out=dir set spec file output directory, default in Pyinstaller directory

--icon=<file. ico> Join icon (Windows only)

-V file,--version=file join version information files

Switch the command-line cmd switch to the directory you are currently packaging

F:\project\pyqt\test>

Enter the command:

Python pyinstaller.py

Wait 5, 6 seconds Pyinstaller after the completion of the compilation, the directory contains more than two folder build and Dist, where dist inside is binary packaging files

--Problems encountered:

When adding an icon to a packaged file, an error

File"C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_-py2.7.egg\PyInstaller\build.py", line 320,inch __postinit__self.assemble () File"C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_-py2.7.egg\PyInstaller\build.py", Line 1245,inchassemble icon. Copyicons (TMPNM, Self.icon) File"C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_-py2.7.egg\PyInstaller\utils\icon.py", Line 170,inchcopyicons hsrc=Win32API. LoadLibraryEx (Srcpath, 0, Load_library_as_datafile) Pywintypes.error: (193,'LoadLibraryEx','%1 \xb2\xbb\xca\xc7\xd3\xd0\xd0\xa7\xb5\xc4 Win32 \xd3\xa6\xd3\xc3\xb3\xcc\xd0\xf2\xa1\xa3')

The icon parameter that I chose at that time was:--icon=favicon.png

The icon format is then changed to Favicon.ico, and the icon parameter cannot be "'" or ' "

Pyinstaller Packaging PYQT Files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.