0

I want to use exactly the same vscode workspace folder on both Windows and Linux. As you may know, contrary to Pycharm, the root folder is unfortunately not included in the python path. So for my workflow, I figured out this solution:

settings.json file :

{
    "terminal.integrated.env.windows": {
        "PYTHONPATH":"${env:PYTHONPATH};${workspaceFolder}",
    },
    "terminal.integrated.env.linux": {
        "PYTHONPATH":"${env:PYTHONPATH}:${workspaceFolder}",
    },
    "python.envFile": "${workspaceFolder}/.env"
}

.env file :

# PYTHONPATH="${PYTHONPATH}:${workspaceFolder}"
PYTHONPATH="${PYTHONPATH};${workspaceFolder}"

It works but as you see, each time I swith from Linux to Windows, I have to swap the PYTHON PATH (";" for windows and ":" for Linux). And of course, I'd like to avoid that.

Please note that :

  • I don't use virtual environnement in this workflow for specific reasons
  • the python.envFile parameter is used by the debugger, not the run.
3
  • Run a script that checks what system you're on and set the right path? Commented Oct 27, 2024 at 20:11
  • Sure, things like print(platform.system()) , print(sys.path), print(os.getenv("PYTHONPATH")). And it works, but I have to change the .env each time. I wish I had something like python.envFile.linux and python.envFile.windows Commented Oct 27, 2024 at 20:38
  • .env files are a bit of a hack to set environment files via a file. You yourself have direct access to the environment itself. You can also load specific environment files based on some logic. Commented Oct 27, 2024 at 21:00

0

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.