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
Had the same problem, found a solution in Pylance's ticket #3473
Try installing with pip install -e . --config-settings editable_mode=strict
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With