PyCharm: ImportError при импорте любого модуля, который импортирует ssl - PullRequest
0 голосов
/ 08 февраля 2019

Я не могу отладить код или запустить консоль Python из-за невозможности импорта ssl.Такое поведение возникает при использовании двух созданных мною виртуальных сред Anaconda.

Например, при попытке отладки кода Python, использующего boto3, я вижу следующую ошибку:

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

КогдаЯ пытаюсь запустить консоль Python и получаю похожую ошибку:

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

Возможно, что-то связано с тем, что я создал новую виртуальную среду в PyCharm и при попытке обновить модуль pip с помощью следующего SSL-произошла связанная ошибка:

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.

Заранее благодарим за любые предложения относительно того, что может быть причиной этой ошибки, как я могу исправить свое окружение и т. д.

1 Ответ

0 голосов
/ 09 февраля 2019

Я недавно столкнулся с той же проблемой с PyCharm.Судя по их сообщению forum , это известная проблема, которая будет исправлена ​​в следующей версии Pycharm 2019.1.Единственный способ обойти это - создать среду, использующую python 3.6.Если вы используете эту среду в качестве интерпретатора, PyCharm должен работать правильно.Надеюсь это поможет.

...