Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install PyQt5 on Windows for Python 2?

Tags:

I am porting a Python 2 app which uses PyQt5 from Linux to Windows.

Question: How do I install PyQt5 on Windows?

What I have tried:

  1. pip install PyQt5 fails with:

    Downloading/unpacking PyQt5
      Could not find any downloads that satisfy the requirement PyQt5
    Cleaning up...
    No distributions at all found for PyQt5
    Storing debug log for failure in C:\Users\user\pip\pip.log
    
  2. Looking for a windows installer on the official website, but there's only PyQt4 installer available for Python 2.

What do I do?

like image 1000
Babken Vardanyan Avatar asked Aug 31 '14 05:08

Babken Vardanyan


People also ask

How do I install PyQt on Windows?

To install PyQt on Windows there are a few steps you need to take. First use the installer from the qt-project website, from qt to install PyQt. Next you want to install a Python version 3.3 or newer. Check the box to add all of the PyQt5 extras.

What is PIP install PyQt5?

Project description PyQt5 is a comprehensive set of Python bindings for Qt v5. It is implemented as more than 35 extension modules and enables Python to be used as an alternative application development language to C++ on all supported platforms including iOS and Android.

Where does PyQt5 get installed?

The PyQt5 Python package will be installed in the directory <DIR> . The default is the Python installation's site-packages directory.

Is PyQt6 better than PyQt5?

As we've discovered, there are no major differences between PyQt5 and PyQt6. The changes that are there can be easily worked around. If you are new to Python GUI programming with Qt you may find it easier to start with PyQt5 still, but for any new project I'd suggest starting with PyQt6.


2 Answers

pip install python-qt5

Installs unofficial PyQt5 via PyPI for Python 2.7 64-bit on Windows

Github for this here: https://github.com/pyqt/python-qt5

like image 132
bigwillydos Avatar answered Sep 26 '22 13:09

bigwillydos


This is a very old question, but had I come across this question with a decent answer a week ago I would have found it very useful. Here's what I did to achieve the desired outcome. As you noted, there aren't supported packages for PyQt5 and Python 2.7 so you will have to build it yourself. Thankfully the process is quite straightforward. By assumption, you already have Python 2.7 installed.

  1. You're going to need a valid installation of MS Visual C++. I have the professional version but I assume that the community version will work too.
  2. You're going to need to have an appropriate version of qt. If you're using 32 bit Python make sure that you get 32 bit Qt. Also, (even though I think that it shouldn't matter), I made sure to get the version of Qt that was built with the same version of the MSVC compiler that I have. This could be important if there is any static linkage between the Qt install and PyQt (which could lead to getting a binary incompatibility of the linked object files.) Get Qt from http://download.qt.io/ Note that Qt has extra considerations around licensing, so you might want to take a look at https://www.qt.io/download/ first.
  3. Make sure that the bin subdirectory of your Qt install is in your system path.
  4. Get the source for SIP. SIP is available from riverbankcomputing.com. I used version 4.18.
  5. There are three commands to build and install SIP. Don't run these commands from a standard shell, use the Visual Studio tools command shell instead, so that your path includes the compiler, and also so that the INCLUDE, LIBS, and LIBPATH environment variables are set.

    python configure.py

    If you're using a virtual environment for Python you might have to modify the makefile for SIPLib since it hard codes dependencies on the location of the Python include subdirectory and the libs subdirectory. I chose to point them at the system Python install (c:\Python27\include and c:\Python27\libs.) It should now be as simple as

    nmake

    nmake install

    The final part of this step is to check that the sip.exe program has been put in a location that is part of your path (this might only be a problem if you're using a virtual Python environment. I copied the program to the scripts directory.)

  6. Get the source for the version of PyQt that corresponds to the version of Qt that you got earlier. It's available from the PyQt project on sourceforge, and the most recent version is available from riverbankcomputing.com.

  7. Repeat the same process of:

    python configure.py

    nmake

    nmake install

    that you used to build SIP. In this case, the number of makefiles that are generated is too large (all potentially with the wrong location of the python27.lib file and the headers, depending on your virtual environment.) I just copied the python27.lib file to the location that the makefiles expect. Similarly, there are three applications that are installed in a location that isn't part of the system path (pyuic5, pyrcc5 and pylupdate5) and I copied these to a location in the path as well.

Done. You should be able to build your PyQt5/Python2.7 application.

like image 27
Peter Du Avatar answered Sep 26 '22 13:09

Peter Du