Setup python in VS Code(cursor)
-
Ensure Pylance extension is installed; It’s the default language server in VS code. And it’s installed alongside with Python extension to provide IntelliSense features.
-
Select python interpreter if you use venv or poetry to manage your project. By default, poetry doesn’t create a .venv folde inside the project. You need to run
poetry config virtualenvs.in-project true
to make it create venv in current project.And then you type
select python interpreter
in Command Palette to select the python interpreter used by your project. It could be the interpreter in .venv or the interpreter in the default poetry venv location.
Note: If you encounter the problem "Pylance(reportMissingImports)", it's most likely because no correct Python interpreter has been selected. VS code uses the default one, eg, the global python.