Python 3.6.x PyInstaller gives error "No module named 'PyQt5.sip'"
Asked Answered
W

2

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.

Wheaton answered 13/7, 2018 at 12:7 Comment(3)
Try to run it in a virtual env.. try pipenv or virtualenvGildea
I'll try it. ThanksWheaton
I did brew install python to upgrade to python 3.7 and it works!!Inoue
G
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.

Gildea answered 13/7, 2018 at 18:13 Comment(7)
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?Wheaton
Yes. Pyqt will default to the os. Use qss to style things. github.com/pyqt/examples/tree/master/widgets/stylesheet/qssGildea
Or alternatively use qt designer if you like a gui for design..tutorialspoint.com/pyqt/pyqt_using_qt_designer.htmGildea
I didn't mean this. I mean default theme. It loses his own default theme. How this should look : how this looks: image link prntscr.com/k6cfm8Wheaton
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 .Gildea
In other words.. If you do not tell it how to look specifically, it will always just "guess"..Gildea
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!Wheaton
Y
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 :(

Yeargain answered 20/5, 2022 at 2:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.