今日呢袱,在用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,結果悲劇了遭顶,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额湘!
~
~
~
不積跬步卿吐,無以至千里