Windows上使用Python2.7安裝pip

之前一直遇到一個問題,就是在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 所需的離線包進行離線安裝,離線包包括以下三個:

  • python-2.7.6.msi
  • setuptools-41.0.1.zip
  • pip-18.1.tar.gz

既:

這三個離線包也可以直接從我的資源上下載,我把這三個資源包打包上傳到我的資源中了: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變量】-> 【新建兩項】

注意:

  • 以上是Win10系統示範
  • Python路徑下的Scripts路徑也要添加到環境變量中,因爲pip.exe 是放在scripts路徑下的。

Windows7 或者 XP 用戶可以使用如下所示設置(其實基本一樣):

【右鍵此電腦】 -> 【屬性】-> 【高級系統設置】-> 【高級】-> 【環境變量】-> 【編輯用戶變量中的Path變量】-> 【把兩個路徑添加到環境變量的末尾】

圖2圖2

注意:

  • 環境變量這裏的每一條路徑需要添加一個分號“:’” 來隔開,
  • 兩個路徑分別是python所在的路徑和pip所在的路徑,既“C:\MyProgramFiles\Python27\;C:\MyProgramFiles\Python27\Scripts;”

經過以上設置之後,重新打開一個控制檯窗口,輸入python --version 和 pip --version,如果能看到版本號信息,就說明安裝成功了,如下圖所示:

圖3

至此,Windows 上使用 python2.7 離線安裝 pip 完成了。  

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章