PyQt5 install by archive extraction

Posted on Fri 28 August 2015 in Technology • 2 min read

We assume you’re trying to build a python qt app on a dev box or a build machine (for a CI setup). You need to install PyQt5 for various reasons including running tests or freezing the setup build.

There are two problem this post will help you solve:

  • Slow downloads of PyQt5
  • Installation of PyQt5 on the box

My experience with sourceforge.net’s download service has not been very good. They are slow and redirect from one mirror to another which confuses downloaders. MirrorService is a great alternative to sf.net downloads. Here’s the link to PyQt5 5.5:

1
https://www.mirrorservice.org/sites/downloads.sourceforge.net/p/py/pyqt/PyQt5/PyQt-5.5/PyQt5-5.5-gpl-Py3.4-Qt5.5.0-x32.exe -FileName $env:temp/pyqt5_install.exe

Onto the second part. PyQt5 installer is based on the NSIS installation scripts. For some reason, the installer didn’t run for me in CI machine. Here’s the alternate way to install PyQt5 (in powershell):

1
2
3
4
5
6
  > cinst 7zip.commandline 
  > c:\programdata\chocolatey\bin\7z.exe x $env:temp\pyqt5_install.exe -oC:\\Python34 -r
  > ls -name "C:\\Python34\\Lib\\site-packages"
  > ls -name "C:\\Python34\\Lib\\site-packages\\PyQt5"
  > Set-Content -Path "C:\\Python34\\Lib\\site-packages\\PyQt5\\pyuic5.bat" -Value "C:\\Python34\\python.exe -m PyQt5.uic.pyuic %1 %2 %3 %4 %5 %6 %7 %8 %9"
  > Get-Content "C:\\Python34\\Lib\\site-packages\\PyQt5\\pyuic5.bat"

We use 7zip version 9.30 or up, which can extract NSIS packages. Older versions will extract the files into a different folder structure like $_OUTDIR etc. and require to move the files again :( We need to extract the files to C:\\Python34 directory preserving the folder structure, so the PyQt5 module ends up in Lib\site-packages\PyQt5.

Last trick is to create a pyuic5.bat file since we’re hacking the installation process (it’d autogenerate for regular installation scenarios).

Complete example is available in the appveyor.yml we’re using for pomito: https://github.com/codito/pomito/blob/master/appveyor.yml.