zmbq
zmbq

Reputation: 39013

VS Code PYTHONPATH for Windows and Linux

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?

Upvotes: 1

Views: 3116

Answers (3)

mike01010
mike01010

Reputation: 6038

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"
    }

Upvotes: 0

Brett Cannon
Brett Cannon

Reputation: 16000

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.

Upvotes: 1

P.S.K
P.S.K

Reputation: 101

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.

Upvotes: 0

Related Questions