vscode: switching between wsl/ubuntu and windows

Question:

I have been doing most of my python development under windows. The app however will be deployed on linux – so i would like to test it on linux. i have installed Ubuntu for windows and WSL extension for vscode. i have also mounted my windows project folder onto my ubuntu instance.
My question is, what is the best/recommended way to switch between windows and wsl/ubuntu using visual studio code…

  1. can the same workspace and settings file be used? my guess is the settings file may not be able to be used given the different location of python
  2. can i use the same virtual environment that i used in windows? again im guessing likely not – given that some libs like pandas have c++ compiled dependencies

given the above, what is the best way to do this? maintain different workspace, settings and virtual environments between ubuntu and windows..but reference the same source code?

thanks for any feedback, recommendations

EDIT: answer to @rioV8 questions:
I had virtual box and had that setup with a share between windows and ubuntu. But now im using Ubuntu LTS – much faster and more snappy it seems, i have set it up with a share to my project folder that i am using under windows. So what i have done so far is:

  1. installed all necessary requirements under Ubuntu for python 3.x

  2. created a new virtual env under my project by pip installing the requirements.txt for my project. So i have two virtual envs under my project now:

    • .venv_win
    • .venv_linux
  3. i can open the project folder in VScode for windows, and another one using the WSL extension for ubuntu

that’s where im at. now im trying to figure out what is the best approach for working under both environments.
My thinking is that maybe another section in the launch.json or settings.json for the two environment? would that work. im trying to figure it out…

Asked By: mike01010

||

Answers:


was able to accomplish this by doing the following:

  1. maintain a linux and windows specific version of an env file: .env and .env_linux

  2. in launch.json, add these to your launch settings:

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

That solves the problem for debugging/running when selecting a debug profile.
Now i only need to figure out how to do this when clicking that ‘Run Python file’ button, which doesnt have a launch setting and seems to default to .env when running the file. but that’s a slightly different problem….

Answered By: mike01010