pip升级失败怎么办

今日,在用pip安装Python包的时候,每次执行完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.

强迫症的笔者,简直忍不了了,果断升级!
怎奈,执拗的笔者没用提示的命令python -m pip install
--upgrade pip
,而是直接pip instrall --upgrade pip,结果悲剧了,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.

报错显示是权限的问题,但是此时pip已经被卸载了

$ 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可以安装最基础版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,重新安装基础班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!

~
~
~


不积跬步,无以至千里

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容