[英]Pip broken after upgrade. Cannot unsinstall or upgrade Pip or Python
I recently had tried to run a pip command and noticed my pip version was considerably out of date so upgraded it.我最近尝试运行 pip 命令,发现我的 pip 版本已经过时了,所以升级了它。 This seems to have completely broken my pip install and I cannot figure out how to reset it.这似乎完全破坏了我的 pip 安装,我不知道如何重置它。
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
You are using pip version 8.1.1, however version 22.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ pip3 install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/f3/77/23152f90de45957b59591c34dcb39b78194eb67d088d4f8799e9aa9726c4/pip-22.1-py3-none-any.whl (2.1MB)
100% |████████████████████████████████| 2.2MB 505kB/s
Installing collected packages: pip
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 22.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ pip3 --version
Traceback (most recent call last):
File "/usr/bin/pip3", line 11, in <module>
sys.exit(main())
File "/home/myname/.local/lib/python3.5/site-packages/pip/__init__.py", line 11, in main
from pip._internal.utils.entrypoints import _wrapper
File "/home/myname/.local/lib/python3.5/site-packages/pip/_internal/utils/entrypoints.py", line 12
f"pip{sys.version_info.major}",
^
SyntaxError: invalid syntax
This seems to come from this: https://github.com/pypa/pip/issues/9526这似乎来自于: https://github.com/pypa/pip/issues/9526
I can't seem to uninstall pip:我似乎无法卸载 pip:
$ python3 -m pip uninstall pip
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/myname/.local/lib/python3.5/site-packages/pip/__main__.py", line 29, in <module>
from pip._internal.cli.main import main as _main
File "/home/myname/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 57
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
I'm on python3.5 and can't seem to upgrade that either:我在 python3.5 上,似乎也无法升级它:
$ sudo apt-get install python3.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.6
E: Couldn't find any package by glob 'python3.6'
E: Couldn't find any package by regex 'python3.6'
I'm found a number of stackoverflow answers suggesting to use alternative repositories but they're not working either.我发现许多建议使用替代存储库的 stackoverflow 答案,但它们也不起作用。
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.6
E: Couldn't find any package by glob 'python3.6'
E: Couldn't find any package by regex 'python3.6'
I've tried 3.6, 3.7, 3.8, 3.9 and 3.10 with the same results.我尝试了 3.6、3.7、3.8、3.9 和 3.10,结果相同。
I've also found some stack overflow answers suggesting to edit /usr/bin/pip3
我还发现了一些建议编辑/usr/bin/pip3
的堆栈溢出答案
Originally it looks like this:最初它看起来像这样:
from pip import main
if __name__ == '__main__':
sys.exit(main())
I've tried this:我试过这个:
from pip._internal import __main__
if __name__ == '__main__':
sys.exit(main())
and this: I've tried this:这个:我试过这个:
from pip._internal import __main__
if __name__ == '__main__':
sys.exit(__main__._main())
But neither have resolved the issue.但都没有解决问题。
To be sure i'm not messed up with a local version i've tried all of the above using /usr/bin/pip3 --version
rather than just pip3 --version
with the same results.为了确保我没有弄乱本地版本,我已经使用/usr/bin/pip3 --version
而不仅仅是pip3 --version
尝试了以上所有操作,结果相同。
Now i'm at a bit of a loss how to get a working version of Python and Pip.现在我有点不知道如何获得 Python 和 Pip 的工作版本。
Suggestion from question:来自问题的建议:
$ sudo python3.5 -m easy_install pip
Searching for pip
Best match: pip 22.1
Adding pip 22.1 to easy-install.pth file
Installing pip3 script to /usr/local/bin
Installing pip3.10 script to /usr/local/bin
Installing pip script to /usr/local/bin
Using /home/myname/.local/lib/python3.5/site-packages
Processing dependencies for pip
Finished processing dependencies for pip
$ ls -lh /usr/local/bin/*pip*
-rwxr-xr-x 1 root root 361 May 12 19:49 /usr/local/bin/pip
-rwxr-xr-x 1 root root 363 May 12 19:49 /usr/local/bin/pip3
-rwxr-xr-x 1 root root 369 May 12 19:49 /usr/local/bin/pip3.10
All 3 return the same thing:所有 3 返回相同的东西:
$ /usr/local/bin/pip --version
$ /usr/local/bin/pip3 --version
$ /usr/local/bin/pip3.10 --version
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module>
load_entry_point('pip==22.1', 'console_scripts', 'pip')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 561, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2291, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2297, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/home/myname/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 57
sys.stderr.write(f"ERROR: {exc}")
^
I've now installed Python3.6 using "method two" from here: https://askubuntu.com/questions/1152640/apt-install-doesnt-install-python3-6 ie manual install我现在已经使用此处的“方法二”安装了 Python3.6: https://askubuntu.com/questions/1152640/apt-install-doesnt-install-python3-6即手动安装
I've then upgraded pip using:然后我升级了 pip 使用:
sudo python3.6 -m pip install pip --upgrade
Now pip --version
and pip3 --version
return an error but directly accessing the bin works:现在pip --version
和pip3 --version
返回错误但直接访问 bin 有效:
$ /usr/local/bin/pip --version
pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
The aliases are currently pointing to:别名当前指向:
$ which pip
/home/sortitoutsi/.local/bin/pip
$ which pip3
/home/sortitoutsi/.local/bin/pip3
It seems that other things are now broken, such as aws
.好像现在其他东西都坏了,比如aws
。
$ aws --help
Traceback (most recent call last):
File "/usr/local/bin/aws", line 19, in <module>
import awscli.clidriver
File "/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py", line 17, in <module>
import botocore.session
File "/usr/local/lib/python2.7/dist-packages/botocore/session.py", line 29, in <module>
import botocore.configloader
File "/usr/local/lib/python2.7/dist-packages/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/usr/local/lib/python2.7/dist-packages/botocore/compat.py", line 26, in <module>
from dateutil.tz import tzlocal
File "/usr/local/lib/python2.7/dist-packages/dateutil/tz/__init__.py", line 1, in <module>
from .tz import *
File "/usr/local/lib/python2.7/dist-packages/dateutil/tz/tz.py", line 16, in <module>
from six import string_types, PY3
ImportError: No module named six
Simply reinstalling aws sudo python -m pip install awscli
seemed to have fixed the above.只需重新安装 aws sudo python -m pip install awscli
似乎就可以解决上述问题。 I'm guessing a sudo apt-get update
at some point forced an upgrade of awscli after finding an updated Python installation.我猜sudo apt-get update
在找到更新的 Python 安装后在某个时候强制升级 awscli。
Do not try and install Python versions and packages (from another ppa) that are not supported by your OS.不要尝试安装您的操作系统不支持的 Python 版本和软件包(来自另一个 ppa)。 Your system may break.您的系统可能会崩溃。
Your attempted Pip
installation is, luckily, in a local directory: $HOME/.local/
.幸运的是,您尝试的Pip
安装在本地目录中: $HOME/.local/
。 Check if there is anything else installed in $HOME/.local/bin/
and $HOME/.local/lib/python3.5/site-packages/
.检查$HOME/.local/bin/
和$HOME/.local/lib/python3.5/site-packages/
中是否安装了其他任何东西。 If nothing (or nothing that seems important), rename that directory:如果什么都没有(或什么都不重要),请重命名该目录:
mv ~/.local ~/.local_aside
Now, you should have the system Pip back again.现在,您应该再次拥有系统 Pip。
You may lose some other packages that you installed earlier (which would now be in ~/.local_aside
, but possibly, you can reinstall those. Either with a system packages (eg, python3-numpy
), or again with pip3 install numpy
and the like. Though pip
may have trouble finding a correct NumPy version, since Python 3.5 is not supported anymore (the system package should be fine).您可能会丢失之前安装的一些其他软件包(现在位于~/.local_aside
中,但您可以重新安装这些软件包。使用系统软件包(例如python3-numpy
),或者再次使用pip3 install numpy
和喜欢。虽然pip
可能无法找到正确的 NumPy 版本,因为不再支持 Python 3.5(系统 package 应该没问题)。
If you want to use a more recent version of Python, install a local (user-only) one.如果您想使用更新版本的 Python,请安装一个本地(仅限用户)版本。 My preferred way of doing that is to use pyenv
, which requires some set up (installing the necessary build packages).我首选的方法是使用pyenv
,这需要进行一些设置(安装必要的构建包)。 If you use pyenv
, carefully read the installation instructions for your case.如果您使用pyenv
,请仔细阅读适用于您的案例的安装说明。 Once you get it going, you can quickly install any version of Python, and between minor versions, they won't even get in the way (that is, python3.9 -m pip install numpy
will be a separate installation from python3.10 -m pip install numpy
, and both can happily live next to each other if so wanted).一旦开始,您可以快速安装Python的任何版本,并且在次要版本之间,它们甚至不会妨碍(即python3.9 -m pip install numpy
将与python3.10 -m pip install numpy
分开安装python3.10 -m pip install numpy
,如果需要的话,两者可以愉快地生活在一起)。
But don't use sudo
and install it as a root: your system will get confused and may break.但是不要使用sudo
并将其安装为根用户:您的系统会变得混乱并可能崩溃。
Another alternative is Conda
, in the form (my preference) of miniconda3
.另一种选择是Conda
,采用miniconda3
的形式(我的偏好)。 Conda can and will also install C library dependencies, and actively tries to resolve version conflicts between Python packages (in case you have to install a lot of packages). Conda 可以并且还将安装 C 库依赖项,并积极尝试解决 Python 包之间的版本冲突(以防您必须安装很多包)。 Again, browse the manual to get going, but it's relatively straightforward to use, and doesn't get in the way of your OS.同样,浏览手册开始使用,但它使用起来相对简单,并且不会妨碍您的操作系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.