Reputation:
After upgrading to PySide6.3.0 getting error ModuleNotFoundError: No module named 'PySide6.QtWidgets'
import sys
from PySide6.QtWidgets import QApplication, QLabel
app = QApplication(sys.argv)
label = QLabel("Hello World!")
label.show()
app.exec()
$ python3.10 test.py
Traceback (most recent call last):
File "test.py", line 2, in <module>
from PySide6.QtWidgets import QApplication, QLabel
ModuleNotFoundError: No module named 'PySide6.QtWidgets'
Seems like there are changes in PySide6.3.0
.
How to import QtWidgets
module in PySide6.3.0
?
It is clear it is importing PySide6 package but its not importing packages like QtWidgets, QtGui, QtCore
#!/usr/bin/env python3.10
import sys
import PySide6
from PySide6 import QtWidgets
from PySide6.QtWidgets import (QApplication, QMainWindow, QWidget, QPushButton, QVBoxLayout, QHBoxLayout)
from PySide6 import QtCore
from PySide6.QtCore import (Qt, QSize)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
#TODO
app.exec()
$ ./test.py
Traceback (most recent call last):
File "./test.py", line 4, in <module>
from PySide6 import QtWidgets
ImportError: cannot import name 'QtWidgets' from 'PySide6' (~/.local/lib/python3.10/site-packages/PySide6/__init__.py)
Upvotes: 7
Views: 18133
Reputation: 1
"from PySide6.QtGui import QAction" fixed the issue. Its not "from PySide6.QtWidgets import QAction".
Upvotes: 0
Reputation: 387
PySide6 move class under PySide6.QtGui. So
from PySide6.QtGui import QDesktopServices
Upvotes: 1
Reputation:
the link provided by @Blackyy helped my resolve this issue.
The problematic bit is because the update doesn't do a 'uninstall/install' and leave some files around, and doesn't override the PySide6 directory with the content of the new two wheels. If you check your site-packages you will see only like 3 modules remained.
The problem occurred when I upgraded PySide6.2.4
to PySide6.3.0
using
$ python3.10 -m pip install --upgrade pyside6
Since we are upgrading the previous packages are left behind and will cause problem when we try to import
modules from pyside6
$ python3.10 -m pip uninstall pyside6 pyside6-addons pyside6-essentials shiboken6
$ python3.10 -m pip cache purge
$ python3.10 -m pip install pyside6
It is necessary to clear cache
files before reinstalling pyside6
other wise it will use previous cache files and the import error
using continue to come.
Upvotes: 12
Reputation: 51
$ python3.10 -m pip install --force-reinstall --no-cache-dir pyside6
No need to pip uninstall
and pip cache clear
Upvotes: 5
Reputation: 66
Try uninstalling PySide6 shiboken6 PySide6-Essentials PySide6-Addons and then reinstall PySide6
See https://bugreports.qt.io/browse/PYSIDE-1891
Upvotes: 5