Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python packages imported in editable mode can't be resolved by pylance in VSCode

I have several Python packages developed locally, which I often use in VSCode projects. For these projects, I create a new virtualenv and install these packages with pip install -e ../path/to/package. This succeeds, and I can use these packages in the project. However, VSCode underlines the package's import line in yellow, with this error:

Import "mypackage" could not be resolved Pylance(reportMissingImports)

Again, mypackage works fine in the project, but VSCode reports that error, and I lose all autocomplete and type hint features when calling mypackage in the project.

I ensured that the right Python interpreter is selected (the one from the project's virtualenv), but the error persists. The error and Pylance docs do not offer any other possible solutions.

VSCode version: 1.78.0

like image 503
Austin de Coup-Crank Avatar asked Sep 04 '25 03:09

Austin de Coup-Crank


2 Answers

Had the same problem, found a solution in Pylance's ticket #3473

Try installing with pip install -e . --config-settings editable_mode=strict

like image 99
AlexOver Avatar answered Sep 06 '25 18:09

AlexOver


Usually, when you choose the correct interpreter, Pylance should take effect immediately. You can try adding "python.analysis.extraPaths": ["path/to/your/package"] to your settings.json.

You can also try clicking on the install prompt in vscode to see which environment it will install the package in. I still believe that the problem was caused by incorrect selection of the interpreter.

like image 22
MingJie-MSFT Avatar answered Sep 06 '25 18:09

MingJie-MSFT