pip 不能用了怎么办
背景
今天在使用 pip install pip -U 命令升级 pip 时没太注意。执行完之后界面好像报了一个错误,当时没在意。结果在安装 mysql 驱动的时候发现报错了。报错信息如下:
Traceback (most recent call last):File "e:\program files\python39\lib\runpy.py", line 197, in _run_module_as_mainreturn _run_code(code, main_globals, None,File "e:\program files\python39\lib\runpy.py", line 87, in _run_codeexec(code, run_globals)File "E:\Program Files\Python39\Scripts\pip.exe\__main__.py", line 4, in <module>ModuleNotFoundError: No module named 'pip'
上面的提示信息很明显。就是因为 pip 升级没成功,导致旧版本删除了,新版本没装上。pip 就这么没了。
解决
这个问题也好解决,分别执行如下两条命令即可:
python -m ensurepippython -m pip install --upgrade pip
执行过程和结果如下:
C:\Users\jerem>python -m ensurepipLooking in links: c:\Users\jerem\AppData\Local\Temp\tmphxj9e51_Requirement already satisfied: setuptools in e:\program files\python39\lib\site-packages (49.2.1)Processing c:\users\jerem\appdata\local\temp\tmphxj9e51_\pip-20.2.3-py2.py3-none-any.whlInstalling collected packages: pipSuccessfully installed pip-20.2.3C:\Users\jerem>python -m pip install --upgrade pipLooking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleCollecting pipUsing cached https://pypi.tuna.tsinghua.edu.cn/packages/7c/02/9ab8b431aca1b46fcc1ac830a5870a28a12ba1abfa681904b1d2da876a86/pip-21.2.1-py3-none-any.whl (1.6 MB)Installing collected packages: pipAttempting uninstall: pipFound existing installation: pip 20.2.3Uninstalling pip-20.2.3:Successfully uninstalled pip-20.2.3Successfully installed pip-21.2.1
通过以上回显可以看出我们已经修复成功了。
验证
使用如下命令验证即可:
pip -V注意:上面的参数是大写的 V
命令回显如下,即可证明安装OK。
C:\Users\jerem>pip -Vpip 21.2.1 from e:\program files\python39\lib\site-packages\pip (python 3.9)
原文:https://www.jeremysong.cn/cn/pip-can-not-used/
欢迎关注我的公众号“须弥零一”,更多技术文章第一时间推送。
评论
