4

I am unable to debug code or run a Python console due to an inability to import ssl. I get this behavior when using two Anaconda virtual environments I have created.

For example when I attempt to debug Python code that uses boto3 I see the following error:

C:\home\miniconda\envs\scw\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 57111 --file C:/home/git/onvif_interact/onvif_interact/notifications.py --config C:\home\data\pullpoint\camera_desk.ini
pydev debugger: process 22816 is connecting

Connected to pydev debugger (build 183.5429.31)
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\pydevd.py", line 1741, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\pydevd.py", line 1735, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\pydevd.py", line 1135, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/home/git/onvif_interact/onvif_interact/notifications.py", line 3, in <module>
    import boto3
  File "C:\home\miniconda\envs\scw\lib\site-packages\boto3\__init__.py", line 16, in <module>
    from boto3.session import Session
  File "C:\home\miniconda\envs\scw\lib\site-packages\boto3\session.py", line 17, in <module>
    import botocore.session
  File "C:\home\miniconda\envs\scw\lib\site-packages\botocore\session.py", line 30, in <module>
    import botocore.credentials
  File "C:\home\miniconda\envs\scw\lib\site-packages\botocore\credentials.py", line 42, in <module>
    from botocore.utils import InstanceMetadataFetcher, parse_key_val_file
  File "C:\home\miniconda\envs\scw\lib\site-packages\botocore\utils.py", line 31, in <module>
    import botocore.httpsession
  File "C:\home\miniconda\envs\scw\lib\site-packages\botocore\httpsession.py", line 7, in <module>
    from urllib3.util.ssl_ import (
ImportError: cannot import name 'ssl' from 'urllib3.util.ssl_' (C:\home\miniconda\envs\scw\lib\site-packages\urllib3\util\ssl_.py)

Process finished with exit code 1

When I attempt to run a Python Console I get a similar error:

C:\home\miniconda\envs\scw\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\pydevconsole.py" --mode=client --port=57152
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\pydevconsole.py", line 5, in <module>
    from _pydev_comm.rpc import make_rpc_client, start_rpc_server, start_rpc_server_and_make_client
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\_pydev_comm\rpc.py", line 4, in <module>
    from _pydev_comm.server import TSingleThreadedServer
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\pydev\_pydev_comm\server.py", line 4, in <module>
    from _shaded_thriftpy.server import TServer
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\third_party\thriftpy\_shaded_thriftpy\server.py", line 9, in <module>
    from _shaded_thriftpy.transport import (
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\third_party\thriftpy\_shaded_thriftpy\transport\__init__.py", line 57, in <module>
    from .sslsocket import TSSLSocket, TSSLServerSocket  # noqa
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.4\helpers\third_party\thriftpy\_shaded_thriftpy\transport\sslsocket.py", line 7, in <module>
    import ssl
  File "C:\home\miniconda\envs\scw\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 procedure could not be found.
Process finished with exit code 1

Something which may be related is that I created a new virtual environment in PyCharm and when I attempted to update the pip module the following SSL-related error occurred:

Collecting pip==19.0.1
  Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
  Could not find a version that satisfies the requirement pip==19.0.1 (from versions: )
No matching distribution found for pip==19.0.1
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
halfer
  • 19,824
  • 17
  • 99
  • 186
James Adams
  • 8,448
  • 21
  • 89
  • 148
  • BTW I have replaced my Miniconda installation with a fresh one and I continue to get the above errors. I installed Python 3.7 from python.org and created a virtual environment based on that and I did not get the above errors so my assumption is that this is somehow related to the Miniconda environment, although the environment has worked well until today. I will next try installing a full Anaconda environment and see if that makes any difference. – James Adams Feb 08 '19 at 22:09

2 Answers2

6

I encountered the same issue with PyCharm recently. Based on their forum post it's a known issue that will be fixed in the next release of Pycharm 2019.1. The only way that I have found to get around this is to create an environment using python 3.6. If you use that environment as your interpreter PyCharm should work properly. Hope this helps.

Mauscow
  • 76
  • 2
  • 3
    EAP release with corresponding fix is already [available](https://www.jetbrains.com/pycharm/nextversion/) – user2235698 Feb 10 '19 at 14:07
  • 1
    I have installed the latest EAP release, but using this version gives no joy -- I still have the same issue with an Anaconda environment using Python 3.7.2. A downgrade of Python to version 3.6.8 fixes things. – James Adams Feb 11 '19 at 15:29
  • Thanks Mauscow!! Your answer was helpful. – rose Apr 29 '19 at 07:52
0

I have already mentioned here that you can go ahead using your conda environment with python 3.7. The only workaround is to copy/paste two dll files to cope with the same issue asked in Python 3.7 anaconda environment - import _ssl DLL load fail error

Elias
  • 743
  • 7
  • 16