Python 3.6.x PyInstaller 报错 "No module named 'PyQt5.sip'"

11

我开发了几个程序,在Python 3.5.4上运行良好,但由于一些关于win32的错误,我转而使用Python 3.6.4。然而,当我使用pyinstaller构建我的项目时,我遇到了以下问题:

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

我尝试重新安装Python,所以我安装了Python 3.6.4/Python 3.6.5,但是我也遇到了这个错误。 无论我构建PyQt5的什么代码,每次都会出现这个错误。

我还尝试将sip.pyd移动到项目文件夹中,但错误仍然发生。 我还尝试过pip install --upgrade sip,但没有帮助。 我还尝试安装pyinstaller的开发版本,但也没有帮助。


尝试在虚拟环境中运行它。尝试使用 pipenvvirtualenv - johnashu
我会尝试的。谢谢。 - Joe Doe
我执行了 brew install python 命令来升级到 Python 3.7 版本,现在它可以正常工作了! - Jeff Hu
2个回答

21

我遇到了同样的问题,这显然是由于现在必须单独安装 sip 导致的已知错误。

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

在创建安装程序时,我添加了以下行:

--hidden-import PyQt5.sip

这个方法可以解决这个问题。


1
这帮助我构建了项目,但是这样做后,我遇到了一个新问题:在构建之后,我的GUI失去了自己的风格(Windows)。我该如何解决? - Joe Doe
是的。Pyqt 将默认为操作系统。使用 qss 来设置样式。https://github.com/pyqt/examples/tree/master/widgets/stylesheet/qss - johnashu
或者,如果您喜欢使用GUI进行设计,可以使用Qt Designer。https://www.tutorialspoint.com/pyqt/pyqt_using_qt_designer.htm - johnashu
1
我不是指这个。我的意思是默认主题。它失去了自己的默认主题。应该是这样的:如何看起来:图像链接http://prntscr.com/k6cfm8 - Joe Doe
2
我通过卸载pyinstaller并安装pyinstaller的develop分支来解决了样式丢失的问题:pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip。非常感谢! - Joe Doe
显示剩余2条评论

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接