Search code examples
pythonpyqtpyqt5pynsist

GUI Built with Pynsist and PyQt: Import Error 'sip'


I have built a GUI using PyQt5 and wanted to distribute it to other computers without Python installed by packageing it with pynsist. Unfortunately, when launching the shortcuts produced by the installer, the GUI does not open as expected and Python keeps crashing (even if Python is instlalled).

The console shows the following error upon crashing:

ModuleNotFoundError: No module named 'sip'.

This is due to from PyQt5.QtCore import *.

Unfortunately, when launching the .launch.py script on a computer with Python installed, everything works fine. I suppose this is because it then targets the installed version instead of the version included in the build of the GUI. However, the shortcuts do not work, no matter if Python is installed, giving me the above error.

Any ideas how to fix this problem and make the shortcuts work on computers that do not have Python installed?

Thank you in advance!


Solution

  • When I first encountered this problem I simply added sip.pyd to my project-folder. You can find it under:

    x:/path-to-python/Lib/site-packages/sip.pyd
    

    but what realy solved my problem was using pyinstaller. It automatically detects most dependencies and most of the time runs without complicated configurations.

    pip install pyinstaller
    pyinstaller main.py 
    # done