pip升級失敗怎么辦

今日,在用pip安裝Python包的時候,每次執(zhí)行完pip命令都會有如下提示

$ pip list |grep PyMySQL
PyMySQL              0.8.0
You are using pip version 19.0.3, however version 19.1.1 is 
available.
You should consider upgrading via the 'python -m pip install 
--upgrade pip' command.

強迫癥的筆者,簡直忍不了了,果斷升級!
怎奈,執(zhí)拗的筆者沒用提示的命令python -m pip install
--upgrade pip
,而是直接pip instrall --upgrade pip,結(jié)果悲劇了,pip升級失敗,原來的pip也被卸載了。

$ pip install --upgrade pip
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
  Downloading 
https://pypi.tuna.tsinghua.edu.cn/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl (1.4MB)
Installing collected packages: pip
  Found existing installation: pip 19.0.3
    Uninstalling pip-19.0.3:
Could not install packages due to an EnvironmentError: [WinError 
5] ????????: 'd:\\python36\\scripts\\pip.exe'
Consider using the `--user` option or check the permissions.

報錯顯示是權(quán)限的問題,但是此時pip已經(jīng)被卸載了

$ pip
Traceback (most recent call last):
  File "d:\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Python36\Scripts\pip.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'

幸好,python -m ensurepip可以安裝最基礎(chǔ)版pip,官方解釋ensurepip如下文,最主要是在說,通常是在跳過pip安裝或者卸載pip時候才會用到該命令。

The ensurepip package provides support for bootstrapping the pip installer into an existing Python installation or virtual environment. This bootstrapping approach reflects the fact that pip is an independent project with its own release cycle, and the latest available stable version is bundled with maintenance and feature releases of the CPython reference interpreter.In most cases, end users of Python shouldn't need to invoke this module directly (as pip should be bootstrapped by default), but it may be needed if installing pip was skipped when installing Python (or when creating a virtual environment) or after explicitly uninstalling pip.

于是,重新填坑,從頭再來:

# step 1,重新安裝基礎(chǔ)班pip
$ python -m ensurepip
Requirement already satisfied: setuptools in d:\python36\lib\site-packag
es
Collecting pip
Installing collected packages: pip
Successfully installed pip-9.0.1

# step 2,更新pip
$ python -m pip install --upgrade pip

OK!

~
~
~


不積跬步,無以至千里

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容