Skip to content

After supersed openssl package, unable import ssl in debug mode #7786

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

Closed
A-hoy opened this issue Oct 6, 2019 · 4 comments
Closed

After supersed openssl package, unable import ssl in debug mode #7786

A-hoy opened this issue Oct 6, 2019 · 4 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@A-hoy
Copy link

A-hoy commented Oct 6, 2019

I use conda to install flake8 package, and it prompts blow:
anaconda_flake8

Before supersed openssl package, the version of openssl:
openssl

After install all of the packages above, i try to run python code (contains 'import ssl') in terminal, it works well.
But when i try to run in debug console (the launch.json setting show in Workspace setting below), it raise import _ssl error, dll load failed.
If i run in Integrated Terminal Debug mode, it will raise error and then activate envrioment. In this case, run in Integrated Terminal Debug mode again without kill terminal, it works well.
This issue is similar to #4300, but in my case, the error only raises when i try to import ssl in debug mode, but it works well in other cases.
This issue can be solved by add 'C:\Users\Zerone\Anaconda3\Library\bin;' to system path environment variable, but obviously not a good solution. So any suggestion to help?

Environment data

  • VS Code version: 1.38.1
  • Extension version (available under the Extensions sidebar): ms-python.python 2019.9.34911
  • OS and version: Windows 7 32-bit (Windows_NT ia32 6.1.7601)
  • Python version (Anaconda3-2019.07-Windows-x86): 3.7.3
  • Type of virtual environment used: conda 4.7.10
  • Relevant/affected Python packages and their versions: openssl 1.1.1c
  • Jedi or Language Server? : False

Workspace setting:

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "Python 3.7: Debug Console",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "internalConsole",
            "pythonPath": "C:\\Users\\Zerone\\Anaconda3\\python.exe"
        },
    ]
}

settings.json

{
    "python.pythonPath": "C:\\Users\\Zerone\\Anaconda3\\python.exe",
    "python.terminal.activateEnvironment": true,
    // Lint
    "python.linting.enabled": true,
    "python.linting.flake8Enabled": true,
    "python.linting.pylintEnabled": false,
    // format
    "editor.formatOnSave": true,
    "python.formatting.provider": "yapf",
}

Expected behaviour

debug test

Actual behaviour

ImportError: DLL load failed

Steps to reproduce:

  1. Install Anaconda3-2019.07-Windows-x86.exe or Anaconda3-2018.12-Windows-x86.exe
  2. Install the latest version of VScode (1.38.1)
  3. Install package flake8 (Anaconda Prompt: conda install -c anaconda flake8)
  4. run below code in Debug Console mode:
import ssl
print('import test')

Debug CONSOLE

Traceback (most recent call last):
  File "c:\Users\Zerone\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "c:\Users\Zerone\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 432, in main
    run()
  File "c:\Users\Zerone\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "C:\Users\Zerone\Anaconda3\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\Zerone\Anaconda3\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\Zerone\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "d:\OneDrive - danpier\Python\Code\Fetch_Urls_Demo\SingleThread_Version\Fetch_Urls.py", line 2, in <module>
    import ssl
  File "C:\Users\Zerone\Anaconda3\lib\ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified module could not be found.
@A-hoy A-hoy added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Oct 6, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Oct 7, 2019
@karthiknadig karthiknadig self-assigned this Oct 7, 2019
@karthiknadig
Copy link
Member

@A-hoy Can you share the debugger command line? This is what you see in the terminal when you start debugging. Also, are you trying to debug a test? It is unclear from the issue where you are running into this. If you are seeing it when you are debugging (like when you hit F5), then i suspect the environment may not have been activated.

@karthiknadig karthiknadig added the info-needed Issue requires more information from poster label Oct 8, 2019
@A-hoy
Copy link
Author

A-hoy commented Oct 8, 2019

@karthiknadig
Debug Console:
debug_console

Integrated Terminal (first time):
terminal_1

Integrated Terminal (second time):
terminal_2

@A-hoy
Copy link
Author

A-hoy commented Oct 12, 2019

The conda developers had mentioned the cause of this issue in docs, see troubleshooting - SSL connection errors and activate-env

Windows is extremely sensitive to proper activation. This is because the Windows library loader does not support the concept of libraries and executables that know where to search for their dependencies (RPATH). Instead, Windows relies on a standard library search order, defined at https://docs.microsoft.com/en-us/previous-versions/7d83bc18(v=vs.140). If environments are not active, libraries won't get found and there will be lots of errors. HTTP or SSL errors are common errors when the Python in a child environment can't find the necessary OpenSSL library.

I also found Pycharm had solved the same issue: PyCharm incorrectly set PATH after conda venv activation
Hope Vscode developers could fix this bug.

@karthiknadig
Copy link
Member

@A-hoy thanks for the detailed repro steps. This is a dupe of #5559. Closing this since the issue is tracked already.

@ghost ghost removed the triage label Oct 17, 2019
@karthiknadig karthiknadig removed the info-needed Issue requires more information from poster label Oct 17, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants