user8234870
user8234870

Reputation:

After upgrading PySide6 gives error No module named 'PySide6.QtWidgets'

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)

Upvotes: 7

Views: 18133

Answers (6)

Maria
Maria

Reputation: 1

"from PySide6.QtGui import QAction" fixed the issue. Its not "from PySide6.QtWidgets import QAction".

Upvotes: 0

sps
sps

Reputation: 1

from PySide6.QtGui import QStandardItem

solved my issue

Upvotes: 0

mcbill
mcbill

Reputation: 387

PySide6 move class under PySide6.QtGui. So

from PySide6.QtGui import QDesktopServices

Upvotes: 1

user8234870
user8234870

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

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.

Upvotes: 12

Stachys
Stachys

Reputation: 51

$ python3.10 -m pip install --force-reinstall --no-cache-dir pyside6

No need to pip uninstall and pip cache clear

Upvotes: 5

Blackyy
Blackyy

Reputation: 66

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

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

Upvotes: 5

Related Questions