5

After upgrading to PySide6.3.0 getting error ModuleNotFoundError: No module named 'PySide6.QtWidgets'

source

import sys
from PySide6.QtWidgets import QApplication, QLabel

app = QApplication(sys.argv)
label = QLabel("Hello World!")
label.show()
app.exec()

error:

$ 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?

Edit:

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()

output:

$ ./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)
Udesh
  • 2,415
  • 2
  • 22
  • 32

3 Answers3

10

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

Solution :

$ 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.

Udesh
  • 2,415
  • 2
  • 22
  • 32
4

Try uninstalling PySide6 shiboken6 PySide6-Essentials PySide6-Addons and then reinstall PySide6

See https://bugreports.qt.io/browse/PYSIDE-1891

Blackyy
  • 56
  • 2
4
$ python3.10 -m pip install --force-reinstall --no-cache-dir pyside6

No need to pip uninstall and pip cache clear

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
Stachys
  • 41
  • 3