11

I developed a few programs that runs well on Python 3.5.4, but because of some errors about win32 made me go to Python 3.6.4, but when I build my project with pyinstaller, I get:

C:\Users\User\Desktop\dist\mycommentator>mycommentator.exe
Traceback (most recent call last):
  File "mycommentator.py", line 6, in <module>
  File "c:\users\user\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
    module = loader.load_module(fullname)
ModuleNotFoundError: No module named 'PyQt5.sip'
[1532] Failed to execute script mycommentator

I tried to reinstall python, so I installed Python 3.6.4/Python 3.6.5, that error happened to me too. No matter what code in PyQt5 I build, every time this error.

I also tried to move sip.pyd to the project folder, but error still happens. I also tried pip install --upgrade sip, that didn't help. I also tried to install the develop version of the pyinstaller, that didn't help too.

Joe Doe
  • 177
  • 1
  • 1
  • 10

2 Answers2

21

I had the same issue which is apparently a known bug due to sip now being installed separately.

https://github.com/pyinstaller/pyinstaller/issues/3630

Upon creating the installer I added the line:

--hidden-import PyQt5.sip

This worked no problem.

johnashu
  • 2,167
  • 4
  • 19
  • 44
  • 1
    That helped to me to build the project, but doing this I have a new problem: after that build my GUI loses his own style (Windows). How can I fix it? – Joe Doe Jul 13 '18 at 20:54
  • Yes. Pyqt will default to the os. Use `qss` to style things. https://github.com/pyqt/examples/tree/master/widgets/stylesheet/qss – johnashu Jul 13 '18 at 23:32
  • Or alternatively use qt designer if you like a gui for design..https://www.tutorialspoint.com/pyqt/pyqt_using_qt_designer.htm – johnashu Jul 13 '18 at 23:33
  • 1
    I didn't mean this. I mean default theme. It loses his own default theme. How this should look : how this looks: image link http://prntscr.com/k6cfm8 – Joe Doe Jul 14 '18 at 09:15
  • Whenever I make something in pyqt without using qss. The results are never the same. Qss or even set stylesheet make sure that what you create in python is what is in the exe . – johnashu Jul 14 '18 at 09:50
  • In other words.. If you do not tell it how to look specifically, it will always just "guess".. – johnashu Jul 14 '18 at 09:55
  • 2
    I fixed losing style problem with uninstalling pyinstaller and installing the develop branch of pyinstaller: `pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip` Thank you very much! – Joe Doe Jul 14 '18 at 15:37
0

I solve this error (python3.10) by adding this code at the top of the main file:

import PyQt5.sip

before this i tried hidden import (https://github.com/pyinstaller/pyinstaller/issues/5381) with no fix :(

Chris P
  • 2,059
  • 4
  • 34
  • 68