1

I need to set the PYTHONPATH for a project in Visual Studio Code. I have an .env file specifying the PYTHONPATH. However, since my path consists of a number of directories, I need to use the following on Windows:

PYTHONPATH=./dirA;./dirB;${PYTHONPATH}

But use colon as a separator on Linux

PYTHONPATH=./dirA:./dirB:${PYTHONPATH}

My .env file is stored in the source repository, as I don't want every person working on the project to figure it out by themselves. I tried setting different env files for Linux and Windows, but setting python.envFile.windows caused the Python extension to fail entirely.

How can I set the Visual Studio Code PYTHONPATH once, in a way that works for developers in both Linux and Windows?

1
  • i have the same issue. makes it a bit burdensome as you have to maintain two separate files for windows vs linux, and have to remember to reference the correct one in settings.json Commented Oct 10, 2022 at 5:04

3 Answers 3

1

There is no OS-specific support for specifying paths to different .env files to specify unique PYTHONPATH values. Please file a feature request at https://github.com/microsoft/vscode-python if you would like to see that implemented.

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

Comments

0

Since you are using vscode, you might need to setup a launch.json file for your project, with at least 2 configurations - one for windows and another for Linux (see the documentation here https://code.visualstudio.com/docs/editor/debugging#_launch-configurations)

You will need to set the environment field in each configuration with the right value for PYTHONPATH.

1 Comment

This is a solution for the launch configurations However, the PYTHONPATH is used by all VS Code extensions. If it's not configured properly, VS Code flags perfectly legal imports as invalid, and doesn't have auto completion for them.
0

Create two .env files. one for linux and one for windows.

In launch.json, add the following:

    "windows": {
        "envFile": "${workspaceFolder}/.env"
    },
    "linux": {
        "envFile": "${workspaceFolder}/.env_linux"
    }

Comments

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.