Search code examples
pythonpyqt4python-3.5pynsist

Bundling a PyQt4 application with pynsist


I am trying to create a installer with pynsist for my python application, which uses PyQt4. I want to bundle the python installation, therefore, I have to use python 3.5, as pynsist supports bundling only for python 3.5. I used a fresh WinPython 3.5.1.1 installation where I installed all the necessary packages and test the installer in a freshly installed Windows 10 virtual box. For building the installer I use the WinPython 3.5.1.1 environment on my Windows 7 machine.

But when I start the installed application, I get an error when QtGui or QtCore is imported:

ImportError: DLL load failed: The specified module could not be found.

Most problems with this error I found in the internet are caused by python not being able to find the dll, but the QtGui4.dll file is present in the pkgs\PyQt4 folder and also copying it to the main folder of the application or the python folder doesn't change anything.

I also tried to export the example PyQt4 application in the pynsist repository with bundling and python 3.5.1 as a minimal example, but I get the same error.

Using the dependency walker in the Windows 10 environment on QtCore.pyd yield: enter image description here There are a lot more "API-MS-WIN*.DLL" dependencies missing, I just scrolled to the part where it seamed to be most "interesting".


Solution

  • The missing dll file is msvcp140.dll.

    This file can be included in the installation by putting this file into the pynsist_pkgs directory next to the .cfg file.

    To load it on runtime the pkgs has to be added to path. This can be done using an extra_preamble file containing:

    os.environ['PATH'] = pkgdir + os.pathsep + os.environ.get('PATH', '')