7

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Reference [here] is missing. Thanks (even if it a long time ago)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.