5

*** Update *** This issue was solved by whiteroom in the comments 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

enter image description here

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?

Emad-ud-deen
  • 4,734
  • 21
  • 87
  • 152

2 Answers2

5

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

whitroom
  • 49
  • 3
  • 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. – Emad-ud-deen Apr 18 '22 at 14:19
  • 1
    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 press **F5** to execute you qt app, **right-click** from vscode file page and find **Qt-options** to crud your ui. If you want to modify your plugins options, press **Ctrl+,**, find **Qt for Python** to do it:) References: [1] https://marketplace.visualstudio.com/items?itemName=seanwu.vscode-qt-for-python – whitroom Apr 19 '22 at 01:00
  • 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? – Emad-ud-deen Apr 19 '22 at 14:13
  • Ahh... I'm not so good at Qt Creator cuz I use **Qt Designer** more than it, but from my experiences, **uic** can translate **.ui** file into **.py** file, you can find **path/to/your/PySide6** to find **uic.exe** to do it. By the way, **Qt for Python** plugins can hot reload translation using **Qt Designer**, which is beneficial for me :) – whitroom Apr 20 '22 at 06:39
  • 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. – Emad-ud-deen Apr 21 '22 at 20:48
  • in my case, only need to run this 'pip install pyside6-essentials' – Chen Wang Jul 14 '23 at 04:57
-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

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 27 '22 at 08:46