vscode python – No module named ‘src’

I've had some issues with running python code in vscode.

I have a project folder.
The code is in the "src" folder running a file one level below

the error

my terminal always said:

    from src.mymodule import *
ModuleNotFoundError: No module named 'src'

The solution

ctrl + p

Preferences: Open Settings (JSON)

append

"terminal.integrated.env.linux": {
    "PYTHONPATH": "${workspaceFolder}/src:${env:PYTHONPATH}"
  },
  "terminal.integrated.env.osx": {
    "PYTHONPATH": "${workspaceFolder}/src:${env:PYTHONPATH}"
  },
  "terminal.integrated.env.windows": {
    "PYTHONPATH": "${workspaceFolder}/src;${env:PYTHONPATH}"
  },

One last step:

close the terminal running it
press on run code again

The issue is discussed here:

https://github.com/microsoft/vscode-python/issues/11875

Leave a Comment