Reputation: 15030
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:
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
Looking for a windows installer on the official website, but there's only PyQt4 installer available for Python 2.
What do I do?
Upvotes: 23
Views: 44685
Reputation: 1371
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
Upvotes: 27
Reputation: 153
There is an interesting guide about installing PyQt5 and SIP for Python2.7: https://blog.synss.me/2018/how-to-install-pyqt5-for-python-27-on-windows/
To recall it, it requires to install first of all the pip and virtualenv modules to create a virtual environment for python where it will be installed. Then, it follows similarly to Peter Du answer. However, I would like to emphasize in the configuration options:
python configure.py ^
--confirm-license ^
--no-designer-plugin ^
--no-qml-plugin ^
--assume-shared ^
--disable=QtNfc ^
--qmake=C:\Qt\%_QTVERSION%\msvc2015\bin\qmake.exe ^
--sip=%VIRTUAL_ENV%\Scripts\sip.exe
In this case, remember that the Qt version should be similar to the version in PyQt.
Another point to highlight is the version. I have probed with the latest version of SIP 4.19.13 and PyQt5 5.11.3, however, even though I could install it correctly, I couldn't launch the module and import it as I have got a error message related to a missing sip module, if using the developer console of Visual Studio, and missing DLL if using in a common console, as pointed out in DLL load failed when importing PyQt5
I've tried also with the SIP 4.19.8 and PyQt5 5.10.1, as the example shown above, however, the PyQt5 in this version have some issues with the Community version of Visual Studio 2017.
Finally, I achieved to install it and launch successfully with SIP 4.19.13 and PyQt5 5.7.1 and Python 2.7.15, as commented by pixebeit in Peter Du answer, using Qt 5.7 (it is installed choosing this version in the list shown by the Qt Maintenance tool) and Visual Studio 2017 Community Edition, with MSVC2015 as the compiler.
NOTE:
If you want to run standalone applications which uses PyQt5 installed by this method, from a conventional CMD, you have two options:
C:\Qt\%_QTVERSION%\msvc2015\bin
to %VIRTUALENV%\Lib\site-packages\PyQt5
if installed in a virtual environment or to C:\Python27\Lib\site-packages\PyQt5
if installed in the base files, as pointed out in https://github.com/x64dbg/PyQt5.C:\Qt\%_QTVERSION%\msvc2015\bin
to the PATH environment variable for Windows.Upvotes: 3
Reputation: 568
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.
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.)
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.
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.
Upvotes: 19