升级 PySide6 后出现错误 No module named 'PySide6.QtWidgets'
After upgrading PySide6 gives error No module named 'PySide6.QtWidgets'
升级到 PySide6.3.0 后出现错误 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'
PySide6.3.0
似乎有变化。
如何在PySide6.3.0
中导入QtWidgets
模块?
编辑:
很明显它正在导入 PySide6 包,但它没有导入 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)
尝试卸载 PySide6 shiboken6 PySide6-Essentials PySide6-Addons 然后重新安装 PySide6
@Blackyy 提供的 link 帮助我解决了这个问题。
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.
当我使用
将PySide6.2.4
升级到PySide6.3.0
时出现问题
$ python3.10 -m pip install --upgrade pyside6
由于我们正在升级以前的软件包,因此当我们尝试从 pyside6
import
模块时会导致问题
解决方案:
$ python3.10 -m pip uninstall pyside6 pyside6-addons pyside6-essentials shiboken6
$ python3.10 -m pip cache purge
$ python3.10 -m pip install pyside6
有必要在重新安装之前清除 cache
个文件 pyside6
否则它将使用以前的缓存文件并且 import error
使用继续。
$ python3.10 -m pip install --force-reinstall --no-cache-dir pyside6
不需要pip uninstall
和pip cache clear
升级到 PySide6.3.0 后出现错误 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'
PySide6.3.0
似乎有变化。
如何在PySide6.3.0
中导入QtWidgets
模块?
编辑:
很明显它正在导入 PySide6 包,但它没有导入 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)
尝试卸载 PySide6 shiboken6 PySide6-Essentials PySide6-Addons 然后重新安装 PySide6
@Blackyy 提供的 link 帮助我解决了这个问题。
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.
当我使用
将PySide6.2.4
升级到PySide6.3.0
时出现问题
$ python3.10 -m pip install --upgrade pyside6
由于我们正在升级以前的软件包,因此当我们尝试从 pyside6
import
模块时会导致问题
解决方案:
$ python3.10 -m pip uninstall pyside6 pyside6-addons pyside6-essentials shiboken6
$ python3.10 -m pip cache purge
$ python3.10 -m pip install pyside6
有必要在重新安装之前清除 cache
个文件 pyside6
否则它将使用以前的缓存文件并且 import error
使用继续。
$ python3.10 -m pip install --force-reinstall --no-cache-dir pyside6
不需要pip uninstall
和pip cache clear