错误代码:
C:\Python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:150: InsecurePlatformWarning: A true SSLContext object is not available.
This prevents
urllib3 from configuring SSL appropriately and may cause certain
SSL connections to
fail. You can upgrade to a newer version of Python to solve this.
For more
information, see https://urllib3.readthedocs.
io/en/latest/advanced-usage.
html#ssl-warnings InsecurePlatformWarning
Could not fetch URL https://pypi.org/simple/pygame/:
There was a problem
onfirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443):
Max etries exceeded with url: /simple/pygame/ (Caused by
SSLError(SSLError(1, _ssl.c:499: error:1407742E:SSL
outines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version'),)) - skipping
出现这个问题的原因是安装源的证书不受信任,可更改pip的配置文件解决这个问题:
更改配置文件首先要知道配置文件在哪,通过阅读pip的源码:
以下是pip源码
if WINDOWS:
bin_py = os.path.join(sys.prefix, 'Scripts')
bin_user = os.path.join(user_site, 'Scripts')
# buildout uses 'bin' on Windows too?
if not os.path.exists(bin_py):
bin_py = os.path.join(sys.prefix, 'bin')
bin_user = os.path.join(user_site, 'bin')
config_basename = 'pip.ini'
legacy_storage_dir = os.path.join(user_dir, 'pip')
legacy_config_file = os.path.join(
legacy_storage_dir,
config_basename,
)
else:
bin_py = os.path.join(sys.prefix, 'bin')
bin_user = os.path.join(user_site, 'bin')
config_basename = 'pip.conf'
legacy_storage_dir = os.path.join(user_dir, '.pip')
legacy_config_file = os.path.join(
legacy_storage_dir,
config_basename,
)
# Forcing to use /usr/local/bin for standard macOS framework installs
# Also log to ~/Library/Logs/ for use with the Console.app log viewer
if sys.platform[:6] == 'darwin' and sys.prefix[:16] == '/System/Library/':
bin_py = '/usr/local/bin'
可以发现
在windows下的路径为: [用户文件夹]/pip/pip.ini
其他系统为:[用户文件夹]/.pip/pip.conf
我是在windows系统下,依次进入 用户 > Administrator
发现并没有pip文件夹。没关系我们可以自己新建一个文件夹命名为pip
并在pip文件夹下创建pip.ini文件
用记事本打开,输入如下配置信息
[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
disable-pip-version-check = true
timeout = 120
[list]
format = columns
index-url 这里设置的为豆瓣源
trusted-host 意思是信任这个地址(这就免去了ssl验证)
disable-pip-version-check = true 设置不检查版本
format = columns 这里是设置使用pip list命令时输出的样式,输入pip config list
效果:
看到这个效果,证明配置文件已经生效了。