Pylance (ReportMissingModuleSource) with Docker

Viewed 1198

I'm getting the error of missing import when doing import in my Django project, I think it's because it's installed in a Docker Container.

But how can I make it so VSCode somehow knows that the packages are installed? If I select an interpreter of a venv in which I have installed django or other packages it doesn't give me that warning, but I don't think creating an venv and installing all the packages there is the right thing. Or maybe it is?

1 Answers

It's recommended to install the packages individually, but if you want to reuse them, you can add the paths of them into the PYTHONPATH.

You can do this to modify the PYTHONPATH:

  1. Add these in the settings.json file to Modify the PYTHONPATH in the terminal:

    "terminal.integrated.env.windows": { "PYTHONPATH": "xxx/site-packages" }

  2. Create a .env file under your workspace, and add these settings in it to modify the PYTHONPATH for the extension and debugger:

    PYTHONPATH=xxx/site-packages

You can refer to here to understand the effects of these two configurations.

Related