【问题标题】:ModuleNotFoundError: No module named 'PySide6' in Python using Visual Studio CodeModuleNotFoundError: No module named \'PySide6\' in Python using Visual Studio Code
【发布时间】:2022-12-27 07:11:31
【问题描述】:

*** Update *** This issue was solved by whiteroom in the cmets section. The issue was that the Python Interpreter setting needed to be changed to point to the correct one. The whiteroom question answer was also very helpful.

*** Original Question *** I installed PySide6 on my MacBook and confirmed that it is installed as shown in the attached screen shot. I'm also very new to Python and using the Mac Terminal app.

pip3 install PySide6

I tried to run this simple app from the Visual Studio Code editor.

from PySide6.QtWidgets import QApplication,QLabel
app   = QApplication([])
label = QLabel('hello world')
label.show()
app.exec()

Python responded with this error:

Traceback (most recent call last):
  File "/Users/emad-ud-deen/Development/Python/Practice/PySide6 Test.py", line 1, in <module>
    from PySide6.QtWidgets import QApplication,QLabel
ModuleNotFoundError: No module named 'PySide6'

The only way I'm able to run the apps I write with PySide6 without that error is from the command line in Terminal.

Can you tell me how to get Visual Studio Code to recognise PySide6?

【问题讨论】:

    标签: python installation pyside6


    【解决方案1】:

    I have the same question with you, but I've just found a solution:

    You can use command like this:

    pip uninstall pyside6-addons
    pip uninstall pyside6-essentials
    pip uninstall pyside6
    pip install pyside6-essentials
    

    Actually, if you don't want to use so difficult plugins, just install PySide6-Essentials[1] is benefit for you :)

    References:

    [1] https://www.qt.io/blog/qt-for-python-details-on-the-new-6.3-release

    【讨论】:

    • Thanks for the answer. I uninstalled and reinstalled PySide6-essentials and tried to execute the test app in Visual Studio Code and also in the Qt Creator. Both responded with the same error. How do I get both editors to recognise PySide6? I can only get the test app to run from Terminal.
    • First, choose correct python interpreter which installed PySide6-Essential from vscode's lower right corner; Second, install Qt for Python vscode plugins[1]. After installed plugins, you can pressF5to execute you qt app,right-clickfrom vscode file page and findQt-optionsto crud your ui. If you want to modify your plugins options, pressCtrl+,, findQt for Pythonto do it:) References: [1] marketplace.visualstudio.com/…
    • Thanks so much! That was it! Visual Studio Code now runs the apps that have the Import PySide6 statements. I hope it's ok to ask a related question. I also have the Qt Creator installed and set the Python Interpreter location like in Visual Studio Code but the software looks for PySide2 and I'm trying to run the same app with the Import PySide6 statement. Do you know where in the Qt Creator I can tell it not to look for PySide2 and change it to look for PySide6?
    • Ahh... I'm not so good at Qt Creator cuz I useQt Designermore than it, but from my experiences,uiccan translate.uifile into.pyfile, you can findpath/to/your/PySide6to finduic.exeto do it. By the way,Qt for Pythonplugins can hot reload translation usingQt Designer, which is beneficial for me :)
    • I'm also now using the designer along with Visual Studio Code. I would like to use Qt Creator but it's just a minor inconvenience to need to flip over to Visual Studio Code instead of just trying to run the app from Qt Creator.
    【解决方案2】:

    you can simply fix this problem by just changing the current version of your python to 3.8.10 from the down-right corner

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      • 2022-08-24
      • 2021-11-22
      • 2022-12-27
      • 2022-12-27
      • 2022-12-27
      • 1970-01-01
      相关资源
      最近更新 更多