Why doesn't VSCode activate conda before starting the debugger?

Related searches

When I start the debugger in VSCode, the conda environment only gets activated after the debugging process has stopped with a "Missing required dependencies" import error. Immediately restarting the debugger works fine then.

This problem occurs with the Anaconda "base" and other environments.

Test code: import_pandas.py

    import pandas
    print("Pandas import succeeded!")

VSCode Python Debug Console:

Microsoft Windows [Version 10.0.16299.1146]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\peter\demo>cd c:\Users\peter\demo && 
    cmd /C "set "PYTHONIOENCODING=UTF-8" && 
    set "PYTHONUNBUFFERED=1" && 
    C:\Users\peter\AppData\Local\Anaconda3\python.exe 
        c:/Users/peter/.vscode/extensions/ms-python.python-2019.5.18678/pythonFiles/ptvsd_launcher.py 
            --default --client --host localhost --port 49530 
c:\Users\peter\demo\import_pandas.py "

...

ImportError: Missing required dependencies ['numpy']

C:\Users\peter\demo>C:/Users/peter/AppData/Local/Anaconda3/Scripts/activate

(base) C:\Users\peter\demo>conda activate base

(base) C:\Users\peter\demo>

Note that conda gets automatically activated after the debugger stopped.

Once after the environment got activated, the debug process doesn't fail anymore:

(base) C:\Users\peter\demo>cd c:\Users\peter\demo && 
    cmd /C "set "PYTHONIOENCODING=UTF-8" && 
    set "PYTHONUNBUFFERED=1" && 
    C:\Users\peter\AppData\Local\Anaconda3\python.exe 
        c:/Users/peter/.vscode/extensions/ms-python.python-2019.5.18678/pythonFiles/ptvsd_launcher.py 
        --default --client --host localhost --port 49544 
c:\Users\peter\demo\import_pandas.py "

Pandas import succeeded!

Is there any way to have conda activated prior to calling the debugger for the first time?

It isn't that the debugger activates conda environments after the debugger stops on purpose, it's that conda activation is so slow it doesn't finish until after the debugger itself finishes (this isn't an issue with virtual environments as they don't need activation to behave appropriately). Basically we ask VS Code to launch a terminal with the activation commands and then launch the debugger, but the debugger is able to get going faster than conda activation, and so it doesn't execute until after the debugger.

Working with conda is just hard. You can follow our meta issue that is tracking all the problems we are trying to solve with the conda team.

Why doesn't the Leaning Tower of Pisa fall over?, If playback doesn't begin shortly, try restarting your device. Your browser does not currently Duration: 5:06 Posted: Dec 3, 2019 To find out why, Menachery has been giving mice at his Texas lab SARS — which is a very close cousin to the new coronavirus. Baby mice at his lab have shaken off the infection, while the older

This seems to fit my problem with Python debugging. My python script works normally in the base conda environment. But as soon as I start the debugger using the Python extension, I immediately start seeing import DLL errors in the debug console, but the debugger does not stop on this error. It simply closes the debugger after 3 seconds or so without executing the script. I can even set breakpoints later in the script and it does not stop after this line. Restarting the debugger does the same, unlike that of the original description. I tried uninstalling then reinstalling the MS Python extension to no avail. Any clues you can offer would be great, I'm not a pro at vs code. Thanks.

Update: I got the debugger working properly. I created a Windows 10 Python virtual environment placed in my project workspace. Apparently this works around the conda env activation delay described below, the delay apparently is not the case with the Windows virtual environment.

Why doesn't Trump try harder to solve the coronavirus crisis?, The president has failed at the one task that could help him achieve all of his goals — confronting the pandemic with a clear strategy and� It's no surprise that President Donald Trump says he won't follow CDC recommendations to wear a mask to stop the spread of coronavirus, writes Michael D'Antonio. Ever the defiant and self-involved

Had the same problem.

Sourcing from: https://github.com/formulahendry/vscode-code-runner/issues/395https://github.com/formulahendry/vscode-code-runner/issues/395

Put this into settings.json:

"code-runner.executorMap": {
    "python": "$pythonPath -u $fullFileName",
}, 
"code-runner.runInTerminal": true,

It does not put "conda activate ..." before the first execution, but it replaces code-runner command from:

"python -u <file path>"

to:

"<virtual environment path> -u <file path>"

This fixed my problem

IT Doesn't Matter, As information technology's power and ubiquity have grown, its strategic importance has diminished. The way you approach IT investment and management will� Why does he keep coming back if he doesn’t want a relationship? So if a guy doesn’t want you, why doesn’t he just let you go? Why does he keep reappearing (and always just when you start moving on)? Well … it’s not always so cut and dry. He may not want a relationship with you, but that doesn’t mean he has zero feelings for you.

Why doesn't Python have a main function? | by Pawan Jain, if __name__ == '__main__' is not function. And the author doesn't recommend it to write this either. Want to know the reasons? but how to write� Why Doesn’t My Goddamn Tupperware Ever Goddamn Dry in the Goddamn Dishwasher? Because of physics, duh! Unloading your dishwasher, you’re faced with two threats: pipin’ hot ceramic dinner plates and Tupperware containers containing a splash-in-the-face quantity of dishwater.

Why Doesn't the U.S. Use the Metric System?, Why Doesn't the U.S. Use the Metric System? Share: Facebook Twitter. WRITTEN BY. Jonathan Hogeback. Editorial intern, Encyclopaedia Britannica. Why doesn’t the U.S. use the metric system? Phil Lewis/shutterstock As of today, the entire world has adopted the metric system, with the exception of the United States, Myanmar, and Liberia.

Why doesn't God perform a spectacular miracle and prove himself? Q: "Why are there no clearly visible miracles today that shout -- without a shadow of a doubt -- to everyone in the world: 'There is a God!'?"

Comments
  • Thanks for the hint. I had already feared that. So at least I can stop looking for settings parameters that somehow change the execution order.
  • You can turn automatic activation off with "python.terminal.activateEnvironment": false if you want.
  • I could manually activate conda via the "terminal.integrated.shellArgs.windows": ["/K", "conda activate py37"] setting. While this works fine with the integrated terminal alone, it doesn't have an impact on the integrated terminal as used by the debugger. However, one problem with the automatic activation is that it first (and unnecessarily) activates the conda base environment and only in the second step the the project environment - and often the debugger starts exactly in between.
  • Thanks for your answer! Virtualenv and pipenv are working fine for me too. It's a conda issue.
  • Thanks for your answer! I already had these lines in my settings, but it didn't solve my problem.