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

Debugging does not work with a conda environment #18436

Closed
kajakIYD opened this issue Feb 4, 2022 · 51 comments
Closed

Debugging does not work with a conda environment #18436

kajakIYD opened this issue Feb 4, 2022 · 51 comments
Assignees
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug investigating We are looking into the cause of the issue

Comments

@kajakIYD
Copy link

kajakIYD commented Feb 4, 2022

Issue Type: Bug

Behaviour

While debugging Python scripts, F5 or "Play button" gives no action - the only thing I see is bar with "stop", "play" and "restart" buttons - but this bar just dissapear after few seconds. In terminal no output is printed.
Since last successful debugging session no system updates or other apps were installed, VSCode is up-to-date.
I have tried restarting VSCode and restarting computer ;)

Linked with:
microsoft/vscode#142154

Expected vs. Actual

Expected: Press F5 button runs code in debug mode.
Actual: After pressing F5 button only "debug bar" appears, but code does not run at all.

Steps to reproduce:

  1. Open VSCode
  2. Open *.py file
  3. Press F5 or "play button" in "Run and debug" section on the left-side-bar of VSCode app window.
launch.json { "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": false } ] }

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.7
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
  • 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: true
• 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: "autopep8"
• 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: true
• executeInFileDir: "<placeholder>"
• launchArgs: "<placeholder>"

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

insidersChannel: "off"

tensorBoard
• logDirectory: "<placeholder>"

Extension version: 2022.0.1786462952
VS Code version: Code 1.64.0 (5554b12acf27056905806867f251c859323ff7e9, 2022-02-03T04:22:20.678Z)
OS version: Windows_NT x64 10.0.19042
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz (8 x 1800)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.90GB (8.45GB free)
Process Argv --folder-uri file:///c%3A/Users/Pawe%C5%82%20Fic/Documents/MOLOS.ANALYTICS/Packages/trend_analysis --crash-reporter-id b5861c78-63a8-433f-adf7-5b3b6a81c16d
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392cf:30425750
pythontb:30283811
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805:30301674
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
vsc1dst:30433059
pythonvs932:30410667
vscop940:30404999
vsrem710cf:30416617

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 4, 2022
@ajrock
Copy link

ajrock commented Feb 4, 2022

Having the same problem since the update to v2022.0.1786462952

@rincewound
Copy link

Same over here. Worked fine yesterday. Got up to VSCode update and it no longer works. The extension seems not to be able to start the debuggee. Before it was broken, one could see the commandline passed to the pyhon interpreter in the terminal of VScode. This no longer happens.

@Rebooorn
Copy link

Rebooorn commented Feb 4, 2022

Also same for me.

Temporarily solved by reloading python IntelliSense to version v2021.12.1559732655.

@knoffelcut
Copy link

knoffelcut commented Feb 4, 2022

Same for me, specifically when using a Conda environment inside a docker container. When using the System interpreter (both host's and docker container's) it works fine.

Had to install 2021.12.1559732655 inside the docker container's vscode to fix it.

@mlamarre
Copy link

mlamarre commented Feb 4, 2022

++same
The Python Debug Console doesn't pop-up like it used to. console=integratedConsole doesn't help.

@XinzeZhang
Copy link

++same

@liaohaofu
Copy link

liaohaofu commented Feb 4, 2022

Same for me, specifically when using a Conda environment inside a docker container. When using the System interpreter (both host's and docker container's) it works fine.

Had to install 2021.12.1559732655 inside the docker container's vscode to fix it.

Same here. This happens only with Conda environment - the other interpreters work fine.

@brettcannon
Copy link
Member

Is anyone not a conda user?

For those that are using conda, this is probably because of https://devblogs.microsoft.com/python/python-in-visual-studio-code-february-2022-release/#improvements-when-using-anaconda . We thought we had this working but apparently there's at least some underlying issue. While we take a look to solve this please feel free to roll back to the 2020.12 release for now and subscribe to this issue to know when we have resolved the problem.

@brettcannon brettcannon changed the title Debugging does not work at all Debugging does not work with a conda environment Feb 4, 2022
@karthiknadig
Copy link
Member

Can some ones share how you created conda environment? Did you use conda create -n env_name or conda create -n env_name python

Are you seeing anything in the terminal when the debugger starts? or the debugger is failing to start entirely? Is there in thing in the Output>Python logs that you can share that might help with this issue?

@brettcannon brettcannon added area-debugging bug Issue identified by VS Code Team member as probable bug investigating We are looking into the cause of the issue and removed triage-needed Needs assignment to the proper sub-team labels Feb 4, 2022
@karthiknadig
Copy link
Member

karthiknadig commented Feb 4, 2022

Can you also share the output of conda info?

@karthiknadig
Copy link
Member

karthiknadig commented Feb 4, 2022

Another thing to test with the debugger, try running this command from any terminal:
Windows: conda run -n env_name --no-capture-output --live-stream python "%USERPROFILE%\.vscode\extensions\ms-python.python-2022.0.1786462952\pythonFiles\lib\python\debugpy\adapter"
Mac/Linux: conda run -n apitest1 --no-capture-output --live-stream python "~/.vscode/extensions/ms-python.python-2022.0.1786462952/pythonFiles/lib/python/debugpy/adapter"

If you are using VS Code server then replace .vscode with .vscode-server in the above command.

If everything is setup as expected, you should see this:
image

If you don't see that, instead you either get an error or nothing happens. That means you might have an unsupported version of conda. Try and update to latest version of conda and see if that helps. We at minimum require conda version 4.9.0.

@d-franzmann
Copy link

Hey,
I also noticed the problem. I attached my conda info to this message. On my windows machine with a newer version of conda I did not experience this problem, on my linux env my debugger failed. I also noticed problems switching my conda env within VSCode with the newest Python extension since yesterday, but I cannot say if this is related to this or not.
My conda env was created via conda create -n env_name .

CondaInfo.txt

Thanks for looking into this issue so fast! Hope I can help with that.

I just noticed your new message while typing. So indeed the conda version in which the debugger is not working is below 4.9.0

@mlamarre
Copy link

mlamarre commented Feb 4, 2022

Conda info (4.10)

condainfo.txt

How the env. is created with docker RUN commands, running vscode-server inside container.

conda_creation.txt

The adapter script above gives a permission error trying to create a temp file in /opt not sure it means something.
condaerror.txt

@mlamarre
Copy link

mlamarre commented Feb 4, 2022

Could be read-only vs writable base environment. Based on two data points.

@karthiknadig
Copy link
Member

@mlamarre That might be different issue with how the environment is set (i.e readonly). That error is coming from conda itself:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.7/site-packages/conda/exceptions.py", line 1079, in __call__
        return func(*args, **kwargs)
      File "/opt/conda/lib/python3.7/site-packages/conda/cli/main.py", line 84, in _main
        exit_code = do_call(args, p)
      File "/opt/conda/lib/python3.7/site-packages/conda/cli/conda_argparse.py", line 83, in do_call
        return getattr(module, func_name)(args, parser)
      File "/opt/conda/lib/python3.7/site-packages/conda/cli/main_run.py", line 26, in execute
        args.dev, args.debug_wrapper_scripts, call)
      File "/opt/conda/lib/python3.7/site-packages/conda/utils.py", line 403, in wrap_subprocess_call
        with Utf8NamedTemporaryFile(mode='w', prefix=tmp_prefix, delete=False) as fh:
      File "/opt/conda/lib/python3.7/site-packages/conda/_vendor/auxlib/compat.py", line 83, in Utf8NamedTemporaryFile
        dir=dir, delete=delete)
      File "/opt/conda/lib/python3.7/tempfile.py", line 547, in NamedTemporaryFile
        (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags, output_type)
      File "/opt/conda/lib/python3.7/tempfile.py", line 258, in _mkstemp_inner
        fd = _os.open(file, flags, 0o600)
    PermissionError: [Errno 13] Permission denied: '/opt/conda/.tmpa3ovoes7'

From my investigation of this issue, it seems like conda < 4.9.0 are failing. This is because those versions did not support streaming io. Which is what the debugger needs to work.

@mlamarre
Copy link

mlamarre commented Feb 4, 2022

But I'm on 4.10 and it still fails with the exact same behaviour as reported at the top of this issue and I have been using the debugger for months and it broke yesterday.

@karthiknadig
Copy link
Member

@mlamarre the cause is different in your case, but the effect is that the debugger does not run. This was probably working before because we did not use conda run to start the debugger instead use the python executable in the conda environment. The change that happened in 2022.0.* is that we started using conda run for environments that we detect as conda.

We used to run the debugger like this. I believe if you use the path to the python binary directly to launch the debugger like below it will start:

<envpath>/python ~/.vscode-server/extensions/ms-python.python-2022.0.1786462952/pythonFiles/lib/python/debugpy/adapter

But running it with conda run looks like this:

/opt/conda/bin/conda run -n base --no-capture-output --live-stream python ~/.vscode-server/extensions/ms-python.python-2022.0.1786462952/pythonFiles/lib/python/debugpy/adapter

If you can try it out (i.e., running debugger using python from env directly), please let me know if it ran.

@karthiknadig
Copy link
Member

@mlamarre You are running into this issue conda/conda#10690 .

@bernardo-suez
Copy link

Same issue
ezgif com-gif-maker
.

@karthiknadig
Copy link
Member

@bernardo-suez Please check your conda version, if it is below 4.9.0 update to the latest version, and see if it helps.

@xmsec
Copy link

xmsec commented Feb 5, 2022

same problem.
and I revert python ext to v2021.12.1559732655, it works.

@siavash-khodadadeh
Copy link

@karthiknadig's suggestion to update Conda from 4.8 to 4.11 also worked for me:
https://docs.anaconda.com/anaconda/install/update-version/

@makhkobek
Copy link

the same issue here, python 3.7, conda 4.7

@ricardoavelino
Copy link

Also had this issue here, working with conda 4.7.11.

Mine worked after updating conda to 4.11.

@makhkobek
Copy link

Also had this issue here, working with conda 4.7.11.

Mine worked after updating conda to 4.11.

Thanks, it worked here as well after updating to conda 4.11

@karthiknadig
Copy link
Member

karthiknadig commented Feb 7, 2022

Can someone here try this build and let me know if it helps with the issue? https://github.com/microsoft/vscode-python/suites/5209242839/artifacts/159283844

We are planning a temporary fix. I still suggest that people update conda to at least 4.9.0

@brettcannon
Copy link
Member

To update everyone: we have a fix merged in #18451 and cherry-picked in #18465 (basically we fall back to the old way of doing things if you're running an old version of conda that doesn't support what we need with conda run). We hope to make a hotfix release today or tomorrow.

But do note we strongly advise any of you on conda <4.9 to upgrade. The extension has been updated across the board to use conda run to give you a better experience/results when we run tools on your behalf (i.e. your conda environment is now activated when we run tools on your behalf). As such, I would expect our support for versions of conda too old to support conda run appropriately to quickly become best-effort.

@NLCharles
Copy link

NLCharles commented Feb 8, 2022

Another workaround is to set a symbolic link to conda env's python interpreter, and add this as a 'new' python interpreter, and debug process will start to work, without conda environment activated, which could be done manually after python debug console pops up. This requires no changes in your conda environment.
Like

ln -s /condapath/envs/envname/bin/python /home/user/python

I believe this is a strong indication that new launcher doesn't work with old conda.

Update:
Running

conda install anaconda; conda update --all

will solve environment inconsistency and repair broken conda environment (especially envs messed up by pip), and after conda update the debugger works.

@phuongnm94
Copy link

same here.
My situation is remote container + conda + python.
Solved by degrading the python extension in VSCode to 2021.12.1559732655.

I updated conda to 4.11, but the problem has not been solved, however degrading the python extension into 2021.12.1559732655 worked with me.

@amarvin
Copy link

amarvin commented Feb 8, 2022

Worked for me after degrading the python extension into 2021.12.1559732655, even with conda 4.6.14

@karthiknadig
Copy link
Member

We just published a fix for the older versions of conda. The fix is in version 2022.0.1814523869.

If you are in a newer version of conda and are experiencing issues, please check the error reported by conda here https://github.com/conda/conda/issues.
you can use the command in the linked comment to run the debugger from a terminal to test if it is working as expected:
#18436 (comment)

@ABotond
Copy link

ABotond commented Feb 8, 2022

The problem still persists for me using VS Code 1.64.1, extension version v2022.0.1814523869 and conda 4.9.1, while using it in SSH remote mode.

It works correctly with v2021.12.1559732655.

@karthiknadig
Copy link
Member

@ABotond Can you try the steps here in the terminal to see if the debugger is able to start in your environment? #18436 (comment)

@ABotond
Copy link

ABotond commented Feb 8, 2022

@karthiknadig Thanks for the quick answer. Indeed, the problem lies here somewhere:

conda run -n base --no-capture-output --live-stream python ~/.vscode-server/extensions/ms-python.python-2022.0.1814523869/pythonFiles/lib/python/debugpy/adapter

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/conda/exceptions.py", line 1079, in __call__
        return func(*args, **kwargs)
      File "/opt/conda/lib/python3.8/site-packages/conda/cli/main.py", line 84, in _main
        exit_code = do_call(args, p)
      File "/opt/conda/lib/python3.8/site-packages/conda/cli/conda_argparse.py", line 83, in do_call
        return getattr(module, func_name)(args, parser)
      File "/opt/conda/lib/python3.8/site-packages/conda/cli/main_run.py", line 25, in execute
        script_caller, command_args = wrap_subprocess_call(on_win, context.root_prefix, prefix,
      File "/opt/conda/lib/python3.8/site-packages/conda/utils.py", line 403, in wrap_subprocess_call
        with Utf8NamedTemporaryFile(mode='w', prefix=tmp_prefix, delete=False) as fh:
      File "/opt/conda/lib/python3.8/site-packages/conda/_vendor/auxlib/compat.py", line 81, in Utf8NamedTemporaryFile
        return NamedTemporaryFile(mode=mode, buffering=buffering, encoding=encoding,
      File "/opt/conda/lib/python3.8/tempfile.py", line 540, in NamedTemporaryFile
        (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags, output_type)
      File "/opt/conda/lib/python3.8/tempfile.py", line 250, in _mkstemp_inner
        fd = _os.open(file, flags, 0o600)
    PermissionError: [Errno 13] Permission denied: '/opt/conda/.tmp2_3bgl4a'

`$ /opt/conda/bin/conda run -n base --no-capture-output --live-stream python /home/guiuser/.vscode-server/extensions/ms-python.python-2022.0.1814523869/pythonFiles/lib/python/debugpy/adapter`

 environment variables:
                 CIO_TEST=<not set>
        CONDA_DEFAULT_ENV=base
                CONDA_EXE=/opt/conda/bin/conda
             CONDA_PREFIX=/opt/conda
    CONDA_PROMPT_MODIFIER=(base)
         CONDA_PYTHON_EXE=/opt/conda/bin/python
               CONDA_ROOT=/opt/conda
              CONDA_SHLVL=1
           CURL_CA_BUNDLE=<not set>
                     PATH=/opt/conda/bin:/opt/conda/bin:/opt/conda/condabin:/home/guiuser/.vscod
                          e-server/bin/d6ee99e4c045a6716e5c653d7da8e9ae6f5a8b03/bin:/usr/local/s
                          bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local
                          /games:/snap/bin
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>

     active environment : base
    active env location : /opt/conda
            shell level : 1
       user config file : /home/guiuser/.condarc
 populated config files : 
          conda version : 4.9.2
    conda-build version : 3.21.4
         python version : 3.8.8.final.0
       virtual packages : __cuda=11.2=0
                          __glibc=2.27=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /opt/conda  (read only)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /opt/conda/pkgs
                          /home/guiuser/.conda/pkgs
       envs directories : /home/guiuser/.conda/envs
                          /opt/conda/envs
               platform : linux-64
             user-agent : conda/4.9.2 requests/2.24.0 CPython/3.8.8 Linux/5.4.0-96-generic ubuntu/18.04.5 glibc/2.27
                UID:GID : 1000:1000
             netrc file : None

Oh, and I'm using conda version 4.9.2, not 4.9.1.

I'm connecting to a docker image (based on pytorch/pytorch:1.8.1-cuda11.1-cudnn8-devel) running an ssh server. I can provide a minimal Dockerfile if needed.

@amarvin
Copy link

amarvin commented Feb 8, 2022

We just published a fix for the older versions of conda. The fix is in version 2022.0.1814523869.

Awesome job! This new version of the Python extension works for me.

@karthiknadig
Copy link
Member

@ABotond You are running into this issue conda/conda#10690 . Please give conda directory write permissions, and it should work. Up vote the conda issue so this gets resolved by them.

@ABotond
Copy link

ABotond commented Feb 8, 2022

@karthiknadig what an ugly hack. But that was it, thanks a lot for your help!

@Raphael-Hao
Copy link

Raphael-Hao commented Feb 9, 2022

In my case, the formatter does not work, even if I upgrade conda to 4.11 and the extension to 2022.0.1814523869. If I downgrade the Python extension to v2021.12.1559732655, it works.
To be specific, I am using a miniconda python installed by pyenv.
When directly executing the formatting command in the terminal, which is presented in the python output window, the output is as follows.

image

@brettcannon
Copy link
Member

@Raphael-Hao please open a separate issue as that's not related to debugging.

@millnerryan
Copy link

I had the same issue, and had nothing to do with the extension version, only with my Conda version. I upgraded conda from 4.10 to 4.11, and even with the latest version of VS Code Python (v2022.0.1814523869), it now works.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug investigating We are looking into the cause of the issue
Projects
None yet
Development

No branches or pull requests