Package the PyQT program on your MAC

Source: Internet
Author: User

There are many people who use Python to write a graphical interface when they choose PyQT, but there are many people who do not know how to package the development of the program into a package, this article I will introduce a very simple and very basic way to package the PyQT program under the MAC.

Installing PYQT Installing QT

We first want to install QT, I installed here, QT 5.5, for the installation of QT on the MAC go directly to the official website to find the corresponding installation package download installation.

http://www.qt.io/

Installing SIP

For SIP, we also need to go to the official website to download the corresponding MAC source package, the installation process is as follows:

python configure.pysudo makesudo make install

If the error message appears in the process Operation not permitted , the solution is as follows: Troubleshooting Mac OS X 10.11 Installation SIP does not have permission issues

Installing PyQT

We need to go to the official website to download the PyQT5 source package, compile and install:

python configure.pysudo makesudo make install

It is important to note that in the make process, we may need to include the QT5 bin directory and the SIP installation directory in the parameters.

Installing Pyinstaller

Execute in Terminal:

sudo pip install pyinstaller

This installs the necessary tools for packaging.

Write a PyQT program

Let's write a simple PyQT program:

mport sysfromimport QApplication, QWidgetif‘__main__‘:    app = QApplication(sys.argv)    w = QWidget()    w.resize(250150)    w.move(300300)    w.setWindowTitle(‘Simple‘)    w.show()    sys.exit(app.exec_())

After execution:

python testqt.py

We will see a QT program:

Package The PyQT program

Here we will package the program written above to become a .app file

We need to run a wrapper on the program's entry file first (for my demo testqt.py ):

pyinstaller --windowed --onefile --clean --noconfirm testqt.py

Let's see what's changed in the following directory:

$ tree.├──build│└──testqt│├──out00-analysis. TOC│├──out00-bundle. TOC│├──out00-exe. TOC│├──out00-pkg. Pkg│├──out00-pkg. TOC│├──out00-pyz. Pyz│├──out00-pyz. TOC│└──warntestqt. txt├──dist│├──testqt│└──testqt. App│└──contents│├──frameworks│├──info. plist│├──macos││└──testqt│└──resources│└──icon-windowed. Icns├──testqt. PY└──testqt. Spec8Directories, -Files

Turn on auto-generated testqt.spec , this is a configuration file:

#-*-Mode:python-*-Block_cipher =NoneA = Analysis ([' testqt.py '], pathex=['/USERS/JASON/PROJECT/PYTHON/PYQT '], binaries=None, datas=None, hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher) Pyz = Pyz (A.pure, A.zipped_data, cipher=block_cipher) exe = EXE (PYZ, A.scripts, A.binaries, A.zipfiles, A.datas, name=' TESTQT ', debug=False, strip=False, upx=True, console=False) app = BUNDLE (EXE, name=' Testqt.app ', icon=None, bundle_identifier=None)

We can modify it to package more complex programs, specifically refer to Pyinstaller official documentation

Here's the last step and we'll be able to package it as a .app file:

pyinstaller --clean --noconfirm --windowed --onefile testqt.spec

We can see that there is dist one more in the directory testqt.app , this is the package we have packaged, double-click, and it will work.

This article's copyright belongs to the author Luo voyage All, uses Attribution-noncommercial 3.0 License. Any person may reproduce, share, but not be used without permission for commercial purposes; reprint please specify the source. Thanks for cooperating!

Package the PyQT program on your MAC

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.