pyuic5 - ModuleNotFoundError: No module named PyQt

2020-06-17 06:33发布

I have just installed Anaconda 5.2 with Python 3.6 on my windows system. Also installed pyqt5 and pyqt5-tools via pip with administrator privilege. Now when I run pyuic5.exe for converting ui files it shows following error:

Traceback (most recent call last):
  File "C:\Users\AshfaqurRahman\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
  File "C:\Users\AshfaqurRahman\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
  File "C:\Users\AshfaqurRahman\AppData\Roaming\Python\Python36\site-packages\PyQt5\uic\pyuic.py", line 26, in <module>
from PyQt5 import QtCore
ModuleNotFoundError: No module named 'PyQt5.sip'

I have tried installing PyQt5-sip package using pip. Buts its already installed in my system.

Why this problem is occurring? How can I solve this problem?

4条回答
家丑人穷心不美
2楼-- · 2020-06-17 07:05

I am a Mac user and I had faced a similar issue. However, I understand for window users, what you are looking for is pyuic5.bat and not pyuic5.sip It seems you'll simply have to provide the full path of the pyuic file(for me, it was under a hidden folder usr in the home directory: /usr/local/Cellar/pyqt/5.10.1_1/bin/pyuic5) and do make sure on your terminal(for you, cmd) you have the directory changed to where the *.ui file lies which you wish to convert to a *.py file.

So for instance, if you have a Qt designer file saved by the name untitled.ui on your desktop, put in the following command in your terminal:

Amars-MacBook-Pro:Desktop amaradak$ /usr/local/Cellar/pyqt/5.10.1_1/bin/pyuic5 -x untitled.ui -o untitled.py

Hope this helps... Cheers

查看更多
闹够了就滚
3楼-- · 2020-06-17 07:08

As of June 2019, pyqt5-tools no longer exists. The solution I found was first installing pyqt5-sip and then install pyqt5

$ pip install pyqt5-sip

$ pip install pyqt5

This seems to get rid of the following error: ModuleNotFoundError: No module named 'PyQt5.sip'

查看更多
劫难
4楼-- · 2020-06-17 07:10

None of the answers above worked for PyQt5 5.13.0 on conda's python 3.6.

With pyqt5 and pyqt5-sip installed just go into python's site-packages and copy sip.so from the PyQt5_sip package to PyQt5 folder (or make a symlink) where the rest of Qt's so modules are.

Seems like a poor decision to pull sip out into a separate package.

查看更多
贼婆χ
5楼-- · 2020-06-17 07:14

According to Agile_Eagle's suggestion from the comments I just uninstalled pyqt5 and pyqt5-tools packages and the reinstalled them. Problem solved!

PS.: If you still got problems with PyQt, try uninstalling all of the PyQt related libraries:

pip uninstall PyQt5
pip uninstall PyQt5-sip
pip uninstall PyQtWebEngine

Then install them again, this will fix:

ModuleNotFoundError: No module named 'PyQt5.sip'
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'

PPS.:If you got problems uninstalling the libraries, go to your Python folder, like C:\Users\<USERNAME>\AppData\Local\Programs\Python\Python<PYTHON-VERSION>\Lib\site-packages and manually delete the PyQt folders, then uninstall everything and install again (Make sure you have the latest Python version and upgraded your pip too)

查看更多
登录 后发表回答