Home > Net >  PyQt5 isn't uderstood from VS Code
PyQt5 isn't uderstood from VS Code

Time:07-13

I have an issue with PyQt5 and VS Code. I have installed PyQt5 on my computer but when I write from VS Code it doesn't work. VS Code underlines my imports with a yellow line and when I run the code it says

from PyQt5 import QtWidgets
ImportError: No module named PyQt5. 

However, when I run the same program from my terminal, it runs fine. My code is

import sys
 
from PyQt5.uic import loadUi
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication, QWidget,QStackedWidget




class Window(QDialog):
    def __init__(self):
        super(Window, self).__init__()
        loadUi("window.ui",self)

app= QApplication(sys.argv)
window = Window()
widget = QStackedWidget()

widget.addWidget(window)
widget.setFixedHeight(800)
widget.setFixedWidth(1200)
widget.show()
try:
    sys.exit(app.exec())
except:
    print("Exiting")

CodePudding user response:

There should be more than one python version installed on your computer, please select the correct python interpreter using:

  1. Ctrl Shift P command to open the Command Palette

  2. search for and select Python:Select Interpreter

    (Or click directly on the python version displayed in the lower right corner)

  3. select the correct interpreter.

enter image description here

  • Related