Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying the Python interpreter in launch.json using the CONDA_PREFIX environment variable raises an error #158

Closed
FSpanhel opened this issue May 12, 2023 · 8 comments
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@FSpanhel
Copy link

FSpanhel commented May 12, 2023

Type: Bug

The following configuration launch.json sets the Python interpreter to the Python interpreter of the activated conda environment of the integrated terminal

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Dynamic path",
            "type": "python",
            "request": "launch",
            "program": "myscript.py",
            "console": "integratedTerminal",
            "cwd": ".",
            "python": "${env:CONDA_PREFIX}/bin/python",
            "justMyCode": true
        },
    ]
}

Wenn I activate the conda environment with the path to the Python interpreter being /conda/envs/my_env/bin/python and then start the debugger of this configuration, I get the following output in the terminal

/usr/bin/env /conda/envs/my_env/bin/python /home/.vscode-server/extensions/ms-python.python-2023.8.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 45096 -- myscript.py
-X is reserved for implementation-specific arguments
usage: /bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

This is unexpected, because the path /conda/envs/my_env/bin/python to the Python interpreter is correct.
Moreover, I have also followed the steps described in https://code.visualstudio.com/docs/editor/variables-reference#_how-can-i-know-a-variables-actual-value to see that the value of the python field in the configuration is actually the path to the Python interpreter.

When I replace the python field in the configuration by /conda/envs/my_env/bin/python the debugger runs.

Extension version: 2023.5.20
VS Code version: Code 1.78.0 (252e5463d60e63238250799aef7375787f68b4ee, 2023-05-03T20:09:00.748Z)
OS version: Windows_NT x64 10.0.19042
Modes:
Sandboxed: No
Remote OS version: Linux x64 4.4.0-19041-Microsoft
Remote OS version: Linux x64 3.10.0-1160.66.1.el7.x86_64
Remote OS version: Linux x64 4.4.0-19041-Microsoft
Remote OS version: Linux x64 4.4.0-19041-Microsoft

System Info
Item Value
CPUs Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz (8 x 2112)
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
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.75GB (1.59GB free)
Process Argv --crash-reporter-id 0d3cf624-62ed-41e9-9c0e-981ac1406d0e
Screen Reader no
VM 0%
Item Value
Remote WSL: Ubuntu-18.04
OS Linux x64 4.4.0-19041-Microsoft
CPUs Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz (8 x 2112)
Memory (System) 15.75GB (1.58GB free)
VM 0%
Item Value
Remote SSH: PROD_ADMIN
OS Linux x64 3.10.0-1160.66.1.el7.x86_64
CPUs Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz (4 x 2294)
Memory (System) 15.51GB (1.41GB free)
VM 100%
Item Value
Remote WSL: Ubuntu-18.04
OS Linux x64 4.4.0-19041-Microsoft
CPUs Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz (8 x 2112)
Memory (System) 15.75GB (1.58GB free)
VM 0%
Item Value
Remote WSL: Ubuntu-18.04
OS Linux x64 4.4.0-19041-Microsoft
CPUs Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz (8 x 2112)
Memory (System) 15.75GB (1.58GB free)
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
282f8724:30602487
pyind779:30671433
f6dab269:30613381
pythonsymbol12:30671437
a9j8j154:30646983
showlangstatbar:30737416
vsctsb:30705553
azdwalk:30721579
pythonms35:30701012
pythonfmttext:30731395
pythoncmvfstr:30731969
fixhidewlkth:30730051
hidesbindicator:30730055

@rchiodo
Copy link

rchiodo commented May 12, 2023

Thanks for the issue. Pylance does not provide the debugger for python, that would be the python extension. Transferring issue there.

@rchiodo rchiodo transferred this issue from microsoft/pylance-release May 12, 2023
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label May 12, 2023
@rchiodo
Copy link

rchiodo commented May 12, 2023

According to this: https://code.visualstudio.com/docs/editor/variables-reference#_environment-variables, I believe that syntax should be supported, but the Python extension may not yet support it.

@karthiknadig karthiknadig self-assigned this May 15, 2023
@karthiknadig
Copy link
Member

@FSpanhel For this to work correctly, VS Code itself must be started from an activated conda environment.

> cd <your project path>
> conda activate <env>
> code .

@karthiknadig karthiknadig added the info-needed Issue requires more information from poster label May 15, 2023
@FSpanhel
Copy link
Author

FSpanhel commented May 16, 2023

@karthiknadig Thank you for your comment.

Unfortunately, this is not what I want. I can achieve the same result by selecting the corresponding Python interpreter in VS Code using the Command Palette and Python: Select Interpreter. This is how I've done it so far when I started debugging with VS Code last week.

However, it would be great if there is a connection between the activated environment in the integrated terminal and the debugger. I tried to achieve this by using the corresponding environment variable in launch.json. As far as I understand the documentation, this should work. And although it appears in my first post that the evaluated path to the Python interpreter is correct, something goes wrong. According to the error message, it appears that somehow the flag -X is passed to the Python interpreter.

Can I somehow investigate what is going on?

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label May 16, 2023
@karthiknadig
Copy link
Member

@FSpanhel That is kind of the problem. Since VS Code launches the debugger the way VS Code can resolve env:CONDA_PREFIX is if VS Code itself was launched from an activated environment so it sees CONDA_PREFIX. That said, we now have a new terminal activation feature that might be able to help with this. This might be a feature request to resolve such variables, based on the activated terminal.

/cc @karrtikr This should work with the new environment variable API for terminal (i.e, we don't have debugger running with a non-activated python issue). Not sure if env:CONDA_PREFIX style of resolution is handled yet.

@FSpanhel
Copy link
Author

@karthiknadig

Okay, so the environment variables of VS Code are determined at startup and are not the environment variables of an integrated terminal that may also change? Is this somewhere documented?

At least to me, reading https://code.visualstudio.com/docs/editor/variables-reference#_environment-variables does not imply such a behavior.

Is there also some documentation about this new "terminal activation feature"?

@karrtikr
Copy link
Contributor

Not sure if env:CONDA_PREFIX style of resolution is handled yet.

Reassigning to debugger as whether this is resolved or not is debugger related.

When I replace the python field in the configuration by /conda/envs/my_env/bin/python the debugger runs.

cc/ @karthiknadig This is all that the new terminal work ensures, it does not control how env variables are resolved.

@karrtikr karrtikr assigned paulacamargo25 and unassigned karrtikr Jul 18, 2023
@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jul 18, 2023
@karrtikr karrtikr removed the info-needed Issue requires more information from poster label Jul 18, 2023
@paulacamargo25 paulacamargo25 transferred this issue from microsoft/vscode-python Dec 14, 2023
@paulacamargo25 paulacamargo25 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2024
@karrtikr
Copy link
Contributor

karrtikr commented Feb 7, 2024

@paulacamargo25 Could you specify a closing comment with the reason for closing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

5 participants