Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Python paths when using VSCode interactive window

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?

like image 304
Abiel Avatar asked Aug 11 '26 11:08

Abiel


1 Answers

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.

like image 114
Steven-MSFT Avatar answered Aug 14 '26 12:08

Steven-MSFT