Skip to content

Debug activates environment too late #11205

Closed

Description

@nironimous

Environment data

  • VS Code version: 1.44.1
  • Extension version (available under the Extensions sidebar): 2020.3.71659
  • OS and version: Windows 10 Pro
  • Python version (& distribution if applicable, e.g. Anaconda): conda
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda

Expected behaviour

When creating the first Python terminal Debug action should activate the conda environment prior to lauching the debug session.

Actual behaviour

The environment is activated after the debug session terminates.

Steps to reproduce:

  1. Set up a simple python
  • use a conda interpreter / environment
  • leave python.terminal.activateEnvironment to true (default)
  1. Close any terminal debug terminal left open.

  2. "Debug" (F5) the script.

Outcome:

A new "Python Debug Console" terminal is created, the debug session is launched and only then the conda environment is activated. Potentially resulting in some un expected error.

Microsoft Windows [version 10.0.18363.720]
(c) 2019 Microsoft Corporation. Tous droits réservés.

C:\_repos\python\vscode\hello> cmd /C "set "DEBUGPY_LAUNCHER_PORT=3680" && C:\tools\miniconda3\envs\test\python.exe c:\Users\bibi\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\wheels\debugpy\launcher 
c:\_repos\python\vscode\hello\.vscode\standardplot.py "
Traceback (most recent call last):
  File "C:\tools\miniconda3\envs\test\lib\site-packages\numpy\core\__init__.py", line 24, in <module>  
    from . import multiarray
  File "C:\tools\miniconda3\envs\test\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
    from . import overrides
  File "C:\tools\miniconda3\envs\test\lib\site-packages\numpy\core\overrides.py", line 7, in <module>  
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed: Le module spécifié est introuvable.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\tools\miniconda3\envs\test\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\tools\miniconda3\envs\test\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\Users\bibi\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\wheels\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\Users\bibi\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\wheels\debugpy/..\debugpy\server\cli.py", line 429, in main
    run()
  File "c:\Users\bibi\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\wheels\debugpy/..\debugpy\server\cli.py", line 266, in run_file
    runpy.run_path(options.target, run_name=compat.force_str("__main__"))
  File "C:\tools\miniconda3\envs\test\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\tools\miniconda3\envs\test\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\tools\miniconda3\envs\test\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\_repos\python\vscode\hello\.vscode\standardplot.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "C:\tools\miniconda3\envs\test\lib\site-packages\matplotlib\__init__.py", line 139, in <module>
    from . import cbook, rcsetup
  File "C:\tools\miniconda3\envs\test\lib\site-packages\matplotlib\cbook\__init__.py", line 32, in <module>
    import numpy as np
  File "C:\tools\miniconda3\envs\test\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\tools\miniconda3\envs\test\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.7 from "C:\tools\miniconda3\envs\test\python.exe",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.18.1" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: DLL load failed: Le module spécifié est introuvable.


C:\_repos\python\vscode\hello>C:/tools/miniconda3/Scripts/activate

(base) C:\_repos\python\vscode\hello>conda activate test

(test) C:\_repos\python\vscode\hello>  

Subsequent debug sessions will produce expected results since the environment is now activated.

Notes

I'm using conda environments. Don't know whether the pb also occurs with other kinds of virtual environments.

Activity

  1. added
    triage-neededNeeds assignment to the proper sub-team
    bugIssue identified by VS Code Team member as probable bug
    on Apr 16, 2020
  2. changed the title [-]Debug activates environment after debug session.[/-] [+]Debug activates environment too late[/+] on Apr 16, 2020
  3. karthiknadig commented on Apr 16, 2020

    @karthiknadig
    Member

    nironimous Our recommendation is to open your workspace folder from anaconda prompt, activate your environment and then start VSCode from there using code .. See #10626

  4. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Apr 16, 2020
  5. karthiknadig commented on Apr 21, 2020

    @karthiknadig
    Member

    Closing this since this is a known issue that we plan on addressing in alternate way as proposed in #10626

  6. ghost removed on Apr 21, 2020
  7. locked as resolved and limited conversation to collaborators on May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue 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