Skip to content

Wrong python interpreter selected in multiroot workspaces when debugging using ${command:python.interpreterPath} #18482

Closed
@gracicot

Description

@gracicot

Issue Type: Bug

Behaviour

Expected vs. Actual

Expected:

  1. Click on the "Debug" green play button from a multi-root workspace
  2. The debugger starts normally, and all import statements works.

Actual:

  1. Click on the "Debug" green play button from a multi-root workspace
  2. The debugger starts, but all import statements for packages installed inside the venv don't work.

Steps to reproduce:

Create a workspace with the following files:

workspace/
  |- python-bug.code-workspace
  |- project1/
  |  |- project1.py
  |- project2/
  |  |- .vscode/
  |  |  |- launch.json
  |  |- project2.py
  |  |- requirements.txt

Here's the content of each files:

python-bug.code-workspace:

{
  "folders": [
    {
      "path": "project1"
    },
    {
      "path": "project2"
    }
  ]
}

project1/project1.py:

print('hello world')

project2/.vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "project2",
      "type": "python",
      "request": "launch",
      "python": "${command:python.interpreterPath}",
      "program": "${workspaceFolder}/project2.py",
      "console": "integratedTerminal"
    }
  ]
}

project2/project2.py:

import pytz
from datetime import datetime
tokyo = pytz.timezone('Asia/Tokyo')
time = datetime.now().astimezone(tokyo).strftime("%Y-%m-%d %H:%M:%S")
print(f"Tokyo time: {time}")

project2/requirements.txt:

pytz==2021.3
  1. Open the workspace in VSCode
  2. Open an integrated terminal in project2
  3. Run python3 -m venv venv in the project2 terminal
  4. Run source ./venv/bin/activate in the project2 terminal
  5. Run pip install -r requirements.txt
  6. Select the python interpreter for project2 to be the one in the venv folder
  7. (Sanity check) Run python project2.py in the project2 console, it should run fine
  8. (Trigger the issue) Click on the launch button in the debug pane of VSCode, an exception occurs

Workaround

Setting the python interpreter to ${workspaceFolder}/venv/bin/python in launch.json solves the problem, so it seem that the python plugin select the wrong interpreter.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.9
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Global
  • Value of the python.languageServer setting: Pylance
User Settings


defaultLS: {"defaultLSType":"Pylance"}

downloadLanguageServer: true

envFile: "<placeholder>"

venvPath: "<placeholder>"

venvFolders: "<placeholder>"

condaPath: "<placeholder>"

pipenvPath: "<placeholder>"

poetryPath: "<placeholder>"

languageServer: "Pylance"

linting
• enabled: true
• cwd: "<placeholder>"
• Flake8Args: "<placeholder>"
• flake8Enabled: false
• flake8Path: "<placeholder>"
• lintOnSave: true
• banditArgs: "<placeholder>"
• banditEnabled: false
• banditPath: "<placeholder>"
• mypyArgs: "<placeholder>"
• mypyEnabled: false
• mypyPath: "<placeholder>"
• pycodestyleArgs: "<placeholder>"
• pycodestyleEnabled: false
• pycodestylePath: "<placeholder>"
• prospectorArgs: "<placeholder>"
• prospectorEnabled: false
• prospectorPath: "<placeholder>"
• pydocstyleArgs: "<placeholder>"
• pydocstyleEnabled: false
• pydocstylePath: "<placeholder>"
• pylamaArgs: "<placeholder>"
• pylamaEnabled: false
• pylamaPath: "<placeholder>"
• pylintArgs: "<placeholder>"
• pylintPath: "<placeholder>"

sortImports
• args: "<placeholder>"
• path: "<placeholder>"

formatting
• autopep8Args: "<placeholder>"
• autopep8Path: "<placeholder>"
• provider: "black"
• blackArgs: "<placeholder>"
• blackPath: "<placeholder>"
• yapfArgs: "<placeholder>"
• yapfPath: "<placeholder>"

testing
• cwd: "<placeholder>"
• debugPort: 3000
• nosetestArgs: "<placeholder>"
• nosetestsEnabled: undefined
• nosetestPath: "<placeholder>"
• promptToConfigure: true
• pytestArgs: "<placeholder>"
• pytestEnabled: false
• pytestPath: "<placeholder>"
• unittestArgs: "<placeholder>"
• unittestEnabled: false
• autoTestDiscoverOnSaveEnabled: true

terminal
• activateEnvironment: false
• executeInFileDir: "<placeholder>"
• launchArgs: "<placeholder>"

experiments
• enabled: true
• optInto: []
• optOutFrom: []

insidersChannel: "off"

tensorBoard
• logDirectory: "<placeholder>"

Extension version: 2022.0.1814523869
VS Code version: Code 1.64.0 (5554b12acf27056905806867f251c859323ff7e9, 2022-02-03T04:20:17.224Z)
OS version: Darwin x64 20.6.0
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz (8 x 2900)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 3, 3, 3
Memory (System) 16.00GB (0.13GB free)
Process Argv --crash-reporter-id 2f97d10c-30e9-44a1-ba46-b0cd71465152
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30425749
pythontb:30283811
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805:30301674
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
testflightcf:30433671
vsc1dst:30433059
pythonvs932:30410667
wslgetstarted:30433507
vs360cf:30404996
vsrem710:30416614
vscscmwlcmt:30433761

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-debuggingbugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions