问题描述
由于无法导入 ssl
,因此我无法调试代码或运行Python控制台。使用两个已创建的Anaconda虚拟环境时,会出现这种情况。
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.
例如,当我尝试调试使用 boto3 $的Python代码时c $ c>我看到以下错误:
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
当我尝试运行Python控制台时,我收到类似的错误:
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
完成这可能是因为我在PyCharm中创建了一个新的虚拟环境,并且当我尝试更新pip模块时,发生了以下与SSL相关的错误:
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.
推荐答案
我最近在PyCharm中遇到了相同的问题。根据他们的帖子,这是一个已知问题,将在下一版Pycharm中修复2019.1。我发现解决此问题的唯一方法是使用python 3.6创建环境。如果您使用该环境作为您的口译员,PyCharm应该可以正常工作。希望这可以帮助。
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.
这篇关于PyCharm:导入任何导入ssl的模块时,ImportError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!