0

I need to re-define the PYTHONPATH within Visual Studio Code (VSC) without it inheriting any values from the default PYTHONPATH set in my shell (zsh).

System Information: macOS: Sonoma 14.6.1, Visual Studio Code: 1.94.0, Python Extension: v2024.16.1, Shell: zsh

Steps I’ve Taken:

  • Created a dev.env file in my workspace.
  • Added the following line in dev.env to set the PYTHONPATH:
    PYTHONPATH="/Users/me/project/utils"
  • Referenced this file in my .code-workspace file as follows:
    "python.envFile": "${workspaceFolder}/dev.env"

Problem: The PYTHONPATH is being modified instead of being set entirely re-defined by the value in the dev.env file.

It starts with the path I defined in dev.env, but it also appends the default PYTHONPATH from my shell. But I need it to replace the PYTHONPATH instead of modifying it.

Additional Attempt: I tried to reset the PYTHONPATH using the following config definition:

"terminal.integrated.env.linux": {
   "PYTHONPATH": null
}

I tried this config in config files/setting below:

  • ~/Library/Application Support/Code/User/settings.json

  • ${workspaceFolder}my_workspace.code-workspace

But this doesn't work either.

Expected Result: I want to ensure that Visual Studio Code uses only the PYTHONPATH specified in the dev.env file, without inheriting or appending values from the shell environment.

Any idea what else I can do? THX

2
  • open a terminal, delete the PYTHONPATH variable, start VSC FROM terminal with code . Commented Oct 19, 2024 at 12:28
  • If you prefer switching to another terminal different from the integrated one(so it won't conflict with environmental variable in your default shell), you may check this out: code.visualstudio.com/docs/terminal/profiles Commented Oct 21, 2024 at 5:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.