欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

运行spyder报错 ModuleNotFoundError: No module named ‘urllib2‘

程序员文章站 2022-03-03 16:21:18
...

windows10下通过Anaconda prompt进入tensorflow环境

在该环境下打开spyder会抛出异常

ModuleNotFoundError: No module named 'urllib2'

(base) C:\Users\qingke3>conda activate tensorflow

(tensorflow) C:\Users\qingke3>spyder
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\spyder\utils\external\github.py", line 51, in <module>
    from urllib2 import build_opener, HTTPSHandler, Request, HTTPError
ModuleNotFoundError: No module named 'urllib2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\tensorflow\Scripts\spyder-script.py", line 10, in <module>
    sys.exit(main())
  File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\spyder\app\start.py", line 214, in main
    mainwindow.main(options, args)
  File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\spyder\app\mainwindow.py", line 3630, in main
    mainwindow = create_window(app, splash, options, args)
  File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\spyder\app\mainwindow.py", line 3488, in create_window
    main.setup()
  File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\spyder\app\mainwindow.py", line 788, in setup
    from spyder.plugins.console.plugin import Console
  File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\spyder\plugins\console\plugin.py", line 39, in <module>
    from spyder.widgets.reporterror import SpyderErrorDialog
  File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\spyder\widgets\reporterror.py", line 28, in <module>
    from spyder.widgets.github.backend import GithubBackend
  File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\spyder\widgets\github\backend.py", line 36, in <module>
    from spyder.utils.external import github
  File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\spyder\utils\external\github.py", line 59, in <module>
    from urllib.request import build_opener, HTTPSHandler, HTTPError, Request
ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (C:\ProgramData\Anaconda3\envs\tensorflow\lib\urllib\request.py)

尝试安装缺失的库 'urllib2'

(tensorflow) C:\Users\qingke3>pip install urllib2
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: 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/urllib2/
WARNING: 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/urllib2/
WARNING: 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/urllib2/
WARNING: 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/urllib2/
WARNING: 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/urllib2/
Could not fetch URL https://pypi.org/simple/urllib2/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/urllib2/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement urllib2
ERROR: No matching distribution found for urllib2
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
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

初步判断异常的关键在于网络传输出错,关注异常

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

检索TLS/SSL的含义

TLS是“安全传输层”协议,SSL是“安全套接层”协议,都属于是加密协议,在其网络数据传输中起到保护隐私和数据的完整性。保证该网络传输的信息不会被未经授权的元素拦截或修改,从而确保只有合法的发送者和接收者才能完全访问并传输信息。

基于SSL module的缺失检索,解决方法是安装或更新windows下的openssl

点击下面链接进入网页

https://slproweb.com/products/Win32OpenSSL.html

选择Win64 OpenSSL v1.1.1j Light 可执行文件(.exe)进行安装

安装完成后重启anaconda prompt,运行spyder即可正常打开

相关标签: 深度学习 spyder