-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Type: Bug
Behaviour
Expect python path to be set based on one of the settings below at runtime
I also posted a question on stackoverflow to see if perhaps im just not doing this correctly: https://stackoverflow.com/questions/74758616/vscode-multi-root-workspace-specifying-python-path-in-env-files
Steps to reproduce:
- basically i would like to conditionally load the python paths based on different .env files driven my the OS im running under, either windows or linux (via WSL). The problem is i cant even get a multi-root workspace to load these paths regardless if i put them in my env file or if put them in my settings.json
This is what the folder structure in vscode looks like:

here are the relevant files' content in my current state - at this point im just adding python paths everywhere given im not sure exactly which of these settings are needed - and the documentation isnt clear with regards to multi-root workspaces how these various means of setting python paths should be ideally set. I'm also just trying to get this to run on windows for now:
project1:launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Run App",
"type": "python",
"request": "launch",
"program": "${workspaceFolder:project1}/src/app/app.py",
"console": "integratedTerminal",
"justMyCode": true,
"windows": {
"envFile": "${workspaceFolder:project1}/.env"
},
"linux": {
"envFile": "${workspaceFolder:project1}/.env_linux"
}
}
]
}
project1: settings.json:
"terminal.integrated.env.windows": {
"python.envFile": "${workspaceFolder:project1}/.env",
"python.pythonPath":"${workspaceFolder:project1}/src:${workspaceFolder:project1}/src/app:${workspaceFolder:project1}/utils",
"PYTHONPATH":"${workspaceFolder:project1}/src:${workspaceFolder:project1}/src/app:${workspaceFolder:project1}/utils",
},
"terminal.integrated.env.linux": {
"python.envFile": "${workspaceFolder:project1}/.env_linux",
},
"python.envFile": "${workspaceFolder:project1}/.env",
.env file
PYTHONPATH=./src:./src/app:./src/utils:./project1/src:./project1/src/utils:./src/app:./src/services
project1:app.py
from utils import utils
So i know it's reading the launch.json located in project1/.vscode, as the debug configuration shows up and i can run->debug.
The problem is when it run the app.py file, at the import above, i see the error:
No module named 'utils'
so that tells me it's not finding the python paths either in the .env file or the settings.json file.
- What it the proper way to loading python path for specific projects in multi-root workspace project
- Can this be done using .env file instead of a settings.json given that at run time, i would be using the .env file and avoids having to maintain python paths for the project in multiple places
- Can we selective load different python paths in vscode depending on wether im running vscode on windows or whether in running on linux (via WSL)
User Settings
Multiroot scenario, following user settings may not apply:
condaPath: "<placeholder>"
languageServer: "Pylance"
Extension version: 2022.20.0
VS Code version: Code 1.74.0 (5235c6bb189b60b01b1f49062f4ffa42384f8c91, 2022-12-05T16:38:16.075Z)
OS version: Windows_NT x64 10.0.22621
Modes:
Sandboxed: No
System Info
| Item | Value |
|---|---|
| CPUs | AMD Ryzen 9 4900HS with Radeon Graphics (16 x 2994) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: disabled_off direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_renderer: enabled_on video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: disabled_off |
| Load (avg) | undefined |
| Memory (System) | 15.42GB (6.24GB free) |
| Process Argv | --crash-reporter-id 769ca7bc-233c-4568-b1c1-d070a7b32662 |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012:30540252
azure-dev_surveyone:30548225
vscccc:30610679
pyindex848cf:30577861
nodejswelcome1:30587005
2e4cg342:30602488
gswce1:30612156
iaj6b796:30613358
dbltrim-noruby:30604474
89544117:30613380
fim-prod:30623723