3

Suppose the Python package mypackage is at a non-standard location on my machine and I am running Python code in the VSCode interactive window. If I type

import mypackage

it will not be found. This can be remedied by doing sys.path.append("/path/to/mypackage"). However, I would like to set things up so that within a given project each time I open the interactive window a set of paths, like /path/to/mypackage, have already been added to the search path. Is there a way to do this?

Abiel
  • 5,251
  • 9
  • 54
  • 74

1 Answers1

1

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][1] to understand the effects of these two configurations.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13