microsoft / debugpy

An implementation of the Debug Adapter Protocol for Python
https://pypi.org/project/debugpy/
Other
1.84k stars 137 forks source link

Specifying python interpreter in launch.json doesn't work on all configurations. #927

Closed Smixi closed 2 years ago

Smixi commented 2 years ago

Issue Type: Bug

Behaviour

Expected vs. Actual

Specifying python interpreter in launch.json doesn't work on all configurations. Example :

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Equipment-SVC",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/../equipment-svc/app.py",
            "console": "integratedTerminal",
            "python": "/home/sami/.local/share/virtualenvs/equipment-svc-yF-tXjDO/bin/python",
            "cwd": "${workspaceFolder}/../equipment-svc",
            "justMyCode": false
        },
        {
            "name": "Datasheets",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/../ftn-datasheets/app.py",
            "console": "integratedTerminal",
            "python": "/home/sami/.local/share/virtualenvs/ftn-datasheets-yeHXxg-Y/bin/python",
            "cwd": "${workspaceFolder}/../ftn-datasheets",
            "justMyCode": false
        },
        {
            "name": "Jobs",
            "type": "python",
            "request": "launch",
            "program": "app.py",
            "env": {
                "PLATFORM": "local",
            },
            "jinja": true,
            "justMyCode": false,
            "python": "/home/sami/.local/share/virtualenvs/job-svc-E0nY6paY/bin/python",
            "cwd": "/home/sami/ngfw/job-svc"
        },
        {
            "name": "MSD",
            "type": "python",
            "request": "launch",
            "program": "app.py",
            "env": {
                "PLATFORM": "local",
            "jinja": true,
            "python": "/home/sami/.local/share/virtualenvs/msd-svc-9Pe5ij5k/bin/python",
            "cwd": "/home/sami/ngfw/msd-svc"
        },
    ],
    "compounds": [
        {
            "name": "FTN All Services",
            "configurations": ["Datasheets", "Equipment-SVC", "Jobs", "MSD"],
        }
    ]
}

Steps to reproduce:

  1. Create a configuration and choose a specific python interpreter.
  2. Launch debug on compound or single one.

Command launched by vscode output:

/usr/bin/env /usr/local/bin/python3.10 /home/sami/.vscode-server/extensio
ns/ms-python.python-2022.4.1/pythonFiles/lib/python/debugpy/launcher 33375 -- /home/sami/fortibfm/workspace
/../equipment-svc/app.py 

For one workspace, it launch almost all service with its own environment (one config is using virtualenv that is not the one specified), for this workspace nothing works. If I source on each integrated terminal, it does work. This was working properly before (something like a week ago).

Diagnostic data

User Settings

``` defaultLS: {"defaultLSType":"Pylance"} downloadLanguageServer: true envFile: "" venvPath: "" venvFolders: "" condaPath: "" pipenvPath: "" poetryPath: "" languageServer: "Pylance" linting • enabled: true • cwd: "" • Flake8Args: "" • flake8Enabled: false • flake8Path: "" • lintOnSave: true • banditArgs: "" • banditEnabled: false • banditPath: "" • mypyArgs: "" • mypyEnabled: false • mypyPath: "" • pycodestyleArgs: "" • pycodestyleEnabled: false • pycodestylePath: "" • prospectorArgs: "" • prospectorEnabled: false • prospectorPath: "" • pydocstyleArgs: "" • pydocstyleEnabled: false • pydocstylePath: "" • pylamaArgs: "" • pylamaEnabled: false • pylamaPath: "" • pylintArgs: "" • pylintPath: "" sortImports • args: "" • path: "" formatting • autopep8Args: "" • autopep8Path: "" • provider: "autopep8" • blackArgs: "" • blackPath: "" • yapfArgs: "" • yapfPath: "" testing • cwd: "" • debugPort: 3000 • nosetestArgs: "" • nosetestsEnabled: undefined • nosetestPath: "" • promptToConfigure: true • pytestArgs: "" • pytestEnabled: false • pytestPath: "" • unittestArgs: "" • unittestEnabled: false • autoTestDiscoverOnSaveEnabled: true terminal • activateEnvironment: false • executeInFileDir: "" • launchArgs: "" experiments • enabled: true • optInto: [] • optOutFrom: [] tensorBoard • logDirectory: "" ```

Extension version: 2022.4.1 VS Code version: Code 1.66.2 (dfd34e8260c270da74b5c2d86d61aee4b6d56977, 2022-04-11T07:46:01.075Z) OS version: Windows_NT x64 10.0.19042 Restricted Mode: No Remote OS version: Linux x64 4.19.0-20-amd64 Remote OS version: Linux x64 4.19.0-20-amd64

System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 5 PRO 3500U w/ Radeon Vega Mobile Gfx (8 x 2096)| |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
oop_rasterization: enabled
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| |Load (avg)|undefined| |Memory (System)|6.88GB (0.68GB free)| |Process Argv|--crash-reporter-id e38c42d0-6509-4484-81c1-2d4dc9b12747| |Screen Reader|no| |VM|0%| |Item|Value| |---|---| |Remote|SSH: dev-fe| |OS|Linux x64 4.19.0-20-amd64| |CPUs|Intel(R) Xeon(R) CPU E5-2658 v4 @ 2.30GHz (2 x 2294)| |Memory (System)|7.76GB (0.99GB free)| |VM|0%| |Item|Value| |---|---| |Remote|SSH: dev-fe| |OS|Linux x64 4.19.0-20-amd64| |CPUs|Intel(R) Xeon(R) CPU E5-2658 v4 @ 2.30GHz (2 x 2294)| |Memory (System)|7.76GB (0.99GB free)| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383cf:30185419 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492:30256859 pythonvspyl392:30443607 pythontb:30283811 pythonptprofiler:30281270 vshan820:30294714 vstes263cf:30335440 pythondataviewer:30285071 vscod805:30301674 pythonvspyt200:30340761 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 vsc1dst:30438360 pythonvs932:30410667 wslgetstarted:30449410 pythonvsnew555:30457759 vscscmwlcmt:30465135 cppdebugcf:30475217 ```

Thanks in advance for your help :) Regards,

int19h commented 2 years ago

The Python interpreter that is used to spawn the launcher is not necessarily the same that'll be used by the launcher to spawn your code - but that mismatch shouldn't be a problem.

Note that the "python" property should generally not be used to pick a different environment - you should be using the Python environment selector in VSCode instead, which takes care of things such as virtualenv activation. The property is provided mainly for advanced scenarios such as custom and embedded interpreters.

@karthiknadig, is there any way to specify the environment per-config (i.e. override the global selector)? If not, it might be a useful feature to have; but it'd have to be done on VSCode side, performing activation and rewriting "python" as needed.

Smixi commented 2 years ago

The Python interpreter that is used to spawn the launcher is not necessarily the same that'll be used by the launcher to spawn your code - but that mismatch shouldn't be a problem.

Oh ok, I thought that it was the one that was executing my code.

Note that the "python" property should generally not be used to pick a different environment - you should be using the Python environment selector in VSCode instead, which takes care of things such as virtualenv activation. The property is provided mainly for advanced scenarios such as custom and embedded interpreters.

I agree, but my use case was that I'm starting compound configuration, where each config, because they are differents service with different requirements.txt file, have differents venv. I'm currently thinking if it was working before or just by luck that all requirements where somehow fullfilled on each services.

Thanks :).

int19h commented 2 years ago

If only one of those needs activation to work properly (this is usually the case for conda), it might be that you had that one selected in the Environments drop-down.

Hyperclaw79 commented 1 year ago

@int19h Why was this issue closed? I have the similar requirement as the OP but need to run the entire compound and I cannot find a way to do it. This is the only thing blocking from migrating to VSCode completely from PyCharm.

int19h commented 1 year ago

It was closed because the behavior as described in the original issue is by design when it comes to debugpy. To summarize, you can use "python" to specify the interpreter to run, overriding whatever was selected by the client (such as e.g. VSCode). But debugpy does not and cannot handle environment activation in the terminal that the client owns, which is why this method may not work with venvs.

This is not to imply that the scenario is invalid! It's just something that needs to be handled in the same place that normally handles Python environments and their activation, which is the VSCode Python extension. We can move this issue over there, but it focuses too much on the specific debugpy setting. It might be better to file a new issue in https://github.com/microsoft/vscode-python laying out the high-level scenario, and then we can discuss what the best VSCode UX to accommodate it would be.

Hyperclaw79 commented 1 year ago

Alright, got it. Thank you.