之前一直遇到一个问题,就是在Windows上使用python2.7安装pip一直不成功,
当时安装的时候使用的脚本是 get-pip.py,安装命令就是 python get-pip.py,然后就报错:
R:\软件\编程软件\pip>python get-pip.py
C:\Program Files\Python2.7\lib\site-packages\distribute-0.6.14-py2.7.egg\setuptools\command\install_scripts.py:3: UserWarning: Module pip was already imported from c:\users\xxx\appdata\local\temp\tmpgvdznh\pip.zip\pip\__init__.py, but c:\program files\python2.7\lib\site-packages\pip-18.1-py2.7.egg is being added to sys.path
from pkg_resources import Distribution, PathMetadata, ensure_directory
c:\users\xxx\appdata\local\temp\tmpgvdznh\pip.zip\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
c:\users\xxx\appdata\local\temp\tmpgvdznh\pip.zip\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: 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/security.html#insecureplatformwarning.
Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [Errno 1] _ssl.c:507: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version - skipping
Requirement already up-to-date: pip in c:\program files\python2.7\lib\site-packages\pip-18.1-py2.7.egg
Collecting wheel
c:\users\xxx\appdata\local\temp\tmpgvdznh\pip.zip\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: 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/security.html#insecureplatformwarning.
Could not fetch URL https://pypi.python.org/simple/wheel/: There was a problem confirming the ssl certificate: [Errno 1] _ssl.c:507: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version - skipping
Could not find a version that satisfies the requirement wheel (from versions: )
No matching distribution found for wheel
c:\users\xxx\appdata\local\temp\tmpgvdznh\pip.zip\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: 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/security.html#insecureplatformwarning.
最后找到的解决方法是下载 安装 pip 所需的离线包进行离线安装,离线包包括以下三个:
既:
这三个离线包也可以直接从我的资源上下载,我把这三个资源包打包上传到我的资源中了:pip_python.zip
安装方法在安装包里面有,其实也很简单,就是先安装 setuptools,再安装 pip,(默认你已经安装了python2.7了,若没有安装python2.7,则可以先安装压缩包中的 python-2.7.6.msi 文件)既:
先安装 setuptools:
进入setuptools 文件夹,运行:python setup.py install
再安装 pip:
进入 pip 文件夹,运行:python setup.py install
最后可以设置一下环境变量,使得你在任何地方打开控制台都能使用 python 和 pip 命令,
设置方法是:
【右键此电脑】 -> 【属性】-> 【高级系统设置】-> 【高级】-> 【环境变量】-> 【编辑用户变量中的Path变量】-> 【新建两项】
注意:
Windows7 或者 XP 用户可以使用如下所示设置(其实基本一样):
【右键此电脑】 -> 【属性】-> 【高级系统设置】-> 【高级】-> 【环境变量】-> 【编辑用户变量中的Path变量】-> 【把两个路径添加到环境变量的末尾】
注意:
经过以上设置之后,重新打开一个控制台窗口,输入python --version 和 pip --version,如果能看到版本号信息,就说明安装成功了,如下图所示:
至此,Windows 上使用 python2.7 离线安装 pip 完成了。