How To Install Pyqt5 For Mac Os

To install PyQt on Mac OS X, you must already have the Xcode tools installed. This is because a compiler and build tool are required to install PyQt. Xcode is a very large package, normally supplied on a separate developer's CD provided with the machine; it is also available online from http://developer.apple. com/tools/xcode. The following instructions assume that Xcode is already installed.

MacHow

Although Macs are normally supplied with a version of Python preinstalled, it may be an old version, in which case we recommend installing an up-to-date version for PyQt development. To check the Python version, start up a Terminal, and type in python -V; if this prints 'Python 2.5', or a higher version number, there is no need to install a new version of Python.

Sep 06, 2020 Guide to install PyQt5 on Mac OS X with python 3.4 virtualenv Description. A simple guide to install PyQt5 on Mac OS X 10.9 (Maverick) and use python 3.4 on a virtualenv. And that’s how you create a desktop app using Python and PyQt5, backed by the awesome Qt5 GUI framework. Instead of writing JavaScript for Electron or C with Qt, you can use Python and Qt to create your next desktop application for Windows, Mac OS X, or Linux. Leave a comment if you try it out, I'd love to know what you think. Install PyQt5 with Python2.7 on Mac. GitHub Gist: instantly share code, notes, and snippets. I have written a nice desktop app in PyQt and it works well on Linux, I was investigating how easy it would be to get it running on a Mac. I have an OS X 10.12 Sierra build running I looked at the homebrew install path method I tried: brew install qt brew install sip brew install pyqt5 When I try to execute my script I see.

The files required for installing PyQt are qt-mac-opensource-4.2.3.dmg, python-2.5.1-macosx.dmg (unless you already have Python 2.5 or later installed), sip-4.6.tar.gz, and, PyQt-mac-gpl-4.2.tar.gz. The book's examples are in the file pyqtbook.tar.gz.

How to install pyqt5 mac os

Start by getting Qt. Go to http://www.trolltech.com/developer/downloads/qt/ index and click the Qt/Mac Open Source Edition link, and near the bottom of the page, download qt-mac-opensource-4.2.3.dmg. A later version number, say, 4.3.1, should also be fine.

If you need to install an up-to-date version of Python, go to http://www.python. org/download and download the Python 2.5.1 for Macintosh OS X version—for example, python-2.5.1-macosx.dmg. A later 2x series version, such as 2.5.2 or

2.6.0, should also be okay, providing they are production releases (not alphas, betas, or release candidates).

How To Install Pyqt5 For Mac Os

The last two tools that must be obtained are SIP and PyQt. Go to http://www. riverbankcomputing.co.uk/sip/download.php and download the source package sip-4.6.tar.gz, then go to, http://www.riverbankcomputing.co.uk/pyqt/download .php and download the source package PyQt-mac-gpl-4.2.tar.gz. Again, the version numbers may be higher—for example, 4.3—for PyQt.

If you want to run the examples that are shown in the book or to see the model answers to the exercises, you can unpack the pyqtbook.tar.gz file available from http://www.qtrac.eu/pyqtbook.html.

Now that all the pieces are at hand, and assuming that Xcode is already installed, you can perform the PyQt installation. Both Qt and Python must be installed first, then SIP, and finally PyQt itself. We will assume that the versions are those mentioned earlier, but obviously, use whichever versions you downloaded and adjust accordingly. We assume that all the downloaded files are on the Desktop, and that you know the administration password (which is normally your own password).

Figure A.4 Installing Qt on Mac OS X

First set up Qt by double-clicking qt-mac-opensource-4.2.3.dmg, or whichever Qt package you downloaded, and following the instructions. The installer's first screen is shown in Figure A.4. We assume that you accept all the defaults and install in the standard locations. Older Qt versions have an unoptimized build tool, and this means that the setup can take a surprisingly long time. More up-to-date versions have an optimized build tool which works much faster.

Figure A.5 Installing Python on Mac OS X

Once Qt is installed, it is time to install Python, if you need to. Doubleclick python-2.5.1-macosx.dmg or the package you downloaded. The installer's first screen is shown in Figure A.5. This may pop up a new window with a MacPython.mpkg file—just double-click this to start up the installer, and follow the instructions. Just as for Qt, we assume that you accept the defaults and install in the standard locations. If you already have one or more older Python versions you will find that these remain intact, with two new Python executables added to /usr/local/bin along with their names, including the version numbers—for example, python2.5 and pythonw2.5. The first executable is used in Terminal windows, and the second is used for running GUI applications and avoids a Terminal from being needlessly popped up in the background.

The installation should make the Python version just installed the default version. To check, close any existing Terminal windows, and then start up a fresh Terminal window, and type python -V. If the version is not the one installed, the settings will need to be changed manually. Close the Terminal, and then in Finder, go to Applications^MacPython 2.5, and start up the Python Launcher. Open the Preferences dialog (shown in Figure A.6), and for each item in the Settings for file type combobox—for Python Scripts, Python GUI Scripts, and Python Bytecode Documents—change the version of Python. For the Python Scripts and Python Bytecode Documents entries, change to /usr/local/bin/python2.5, and for the Python GUI Scripts entry, change to /usr/local/bin/pythonw2.5 (note the 'w' in the executable's name). These values may not be available in the drop-down lists, in which case they must be typed in manually. For each entry, also be sure to uncheck the Run in a Terminal window checkbox.

Both SIP and PyQt must be built in a Terminal. Close all open Terminals, and then start a fresh one. Type python -V to make sure that the correct Python is be-

Figure A.6 Setting which Python to use on Mac OS X

ing used. If it is not, see the preceding paragraph; alternatively, enter the full name of the version of Python you want to use—for example, python2.5 con-figure.py.

SIP must be built first, by typing the following into the Terminal:

cd $HOME/Desktop tar xvfz sip-4.6.tar.gz cd sip-4.6

python configure.py make sudo make install

You will be asked for the administration password (normally your own password) when you execute the sudo command at the end. Now, PyQt can be installed.

cd $HOME/Desktop tar xvfz PyQt-mac-gpl-4.2.tar.gz cd PyQt-mac-gpl-4.2 python configure.py make sudo make install

Again, you will be prompted for a password when you execute the sudo command. Building PyQt can take quite a long time, so you will need to be patient.

The Qt documentation is available through Qt Assistant, which can be run from Finder. PyQt's documentation is supplied in HTML format in the $HOME/Desktop/PyQt-mac-gpl-4.2/doc directory. It is worthwhile moving this somewhere permanent and adding a suitable bookmark to your browser. It also comes with numerous examples; at the very least it is worth looking at the PyQt examples and running the demo. (For example, change the directory to $HOME/Desktop/PyQt-mac-gpl-4.2/examples/tools/qtdemo and run ,/qtdemo.py.)

If you downloaded the book's examples, you might like to unpack pyqtbook. tar.gz in $HOME to get a $HOME/pyqt directory with all the book's examples, and model answers to the exercises, categorized by chapter. In the $HOME/pyqt directory itself you will find mkpyqt.py and makepyqt.pyw; you might like to move (or soft-link) these to a directory on your $PATH—for example, $HOME/bin—to make them more convenient to use. Some of the examples depend on Qt Designer .ui files or on .qrc resource files. How to turn these into Python modules is covered on page 207, but for now it might be convenient to simply perform the conversions:

This will convert any .ui and .qrc files that are found in the pyqt directory and in its subdirectories.* If you prefer to use the GUI makepyqt.pyw tool, you may have to click its More—Tool paths option and set the path to pyuic4. It may also be necessary to set the paths to the other tools too.

How To Install Pyqt5 For Mac Os 64-bit

This completes the installation for Mac OS X. If you unpacked the examples, you could go to the Desktop and click the pyqt directory, then the chap12 directory, and then click multipedes.pyw to see a graphics application. If an unwanted Terminal window pops up, right-click multipedes.pyw, and click the Info dialog; change the Open with setting to the Python Launcher for the correct version of Python, and apply the change to all files with the .pyw suffix.

You are now ready to write and run PyQt applications on your Mac OS X machine—and they will run unchanged on Windows and Linux too!

Was this article helpful?

PyInstaller has only preliminary support for Mac OS-X and currently (Feb. 2010) needs some workarounds and modifications to work properly with PyQt. Therefore this short how-to will show the steps to make the QtWebKit based 'Minibrowser' sample app from here into an OS-X application bundle.

Prerequisites

  • Recent versions of Qt and PyQt need to be installed.

I installed PyQt and Eric4 according to this guide. The following versions were used: OS-X 10.6.2, Python 2.6.1, Qt 4.6.2., PyQt 4.7, sip 4.10, QScintilla 2.4.2. Eric4 is obviously optional for the purpose of this how-to.

Installing and patching PyInstaller

  • Create a working folder, for example:
    • /Users/username/pywork
    • Open a Terminal window and
  • Download the current pyinstaller source:
    • > Checked out revision 771

  • Modify pyinstaller/source/linux/main.c by commenting out the following 'wait()' section at the end of the file:
    • This deals with the problem 'Icon and Menu is missing from PyQt apps, when running an OS-X App Bundle'. The patch is described and can be downloaded here.

  • Setup pyinstaller:
  • Patch Build.py, otherwise we get a 'Python image not found error'
    • Browse to Ticket #152 'pyinstaller onefile fails to bundle Python framework shared lib on osx'

    • Download pyinstaller.patch and copy it into pywork/pyinstaller

Making the Application into an App Bundle

  • Download a the Minibrowser sample project:
    • From here into the pywork directory and unzip

  • In the main loop add window.raise_():
    • this deals with the PyQt specific problem in OS-X, that an application window is not automatically brought to the front on launch as expected. link

    • for example in pywork/minibrowser/minibrowser.py modify as follows
  • Change to the pywork directory & make the spec file:

  • Add the following to the bottom of your spec file:
  • Build the Application Bundle:
  • Fix the Bundle:
    • Change the key in pywork/Minibrowser.app/Contents/Info.plist to
  • To deal with the issue 'OS-X App Bundle is missing most files' described here

    • Copy the missing app files into pywork/Minibrowser.app/Contents/MacOS:
  • To prevent the Error: 'qt_menu.nib could not be loaded' described here

    • Into the pywork/Minibrowser.app/Contents/Resources folder copy qt_menu.nib from /Library/Frameworks/QtGui.framework/Versions/4/Resources/qt_menu.nib

How To Install Pyqt5 Designer

Test and Compress the App

  • You should now be able to run the application bundle just like any native OS-X application by double clicking on it.
  • Minibrowser usage: Enter a url and click the Navigate button

  • Package the app in a compressed dmg for distribution, this reduces the size to about one third.

Install Pyqt5 Tools

Check the linked issue tickets and PyInstaller tracker and release notes, as these issues will be resolved sometime and the steps with workarounds will hopefully not be needed any more.