tjati
tjati

Reputation: 6069

VS Code + Pylance does not find venv-installed modules while venv is activated

I use VS Code Version: 1.74.3 on MacOS 13.2. python -V returns Python 3.11.1.

I get the following error message: Import "django.shortcuts" could not be resolved from source Pylance(reportMissingModuleScource).

enter image description here

As you can see in the screenshot, the correct venv is activated and includes Django.

enter image description here

I also tried or checked:

  1. Import could not be resolved/could not be resolved from source Pylance in VS Code using Python 3.9.2 on Windows 10
  2. https://stackoverflow.com/a/65802367/2321643 but
  3. the suggested solution with reloading the windows did not help.
  4. reinstallation the virtual environment within VSCode and installing Django again
  5. re-selecting the venv.
  6. deleting all python-specific settings in user/settings.json as well as .vcode/settings.json.
  7. Reinstallation python and associated extensions.

Using Debug I can safely run my Django-application without any import issues. What do I need to do that Pylance does not issues these problems?

Upvotes: 5

Views: 6595

Answers (3)

cliff
cliff

Reputation: 51

Sometimes it may so happen that you move your main folder and forget to update the new path in the Pylance icon on the window's down-right side. Just updating to the new path worked for me.

Upvotes: 0

tjati
tjati

Reputation: 6069

My issue was a bug, fixed and closed.

For reference: https://github.com/microsoft/pylance-release/issues/3881

Upvotes: 1

Salaah Amin
Salaah Amin

Reputation: 442

Try clicking on where it says "3.11.1 ('.venv': venv)" (near the bottom right). It should bring up a little dialog sort of thing at the top where you can verify that the Python path is correct.

Check that it is using the correct Python path. It should be something like venv/bin/python3 or venv/bin/python assuming venv is situated at the root of youur project.

Upvotes: 4

Related Questions