本来想安装一个库,但是不知怎么把pip版本升级了之后,一直报这个错误,尝试网上说的其他办法,但是因为和pip相关的全部命令都无法使用,所以无法删除typing,在目录下手动删除相关文件之后还是不行。后来使用如下命令用轮子安装旧版本的pip:
pip install --target=/root/anaconda3/envs/torch/lib/python3.6/site-packages pip-20.1-py2.py3-none-any.whl
注意不要添加 --user
根据这个网址,解释如下:
pundle uses --target pip feature to install package to dedicated path. So somewhere in your system --user option is configured. You need to turn it off. Also you can give a try to pyenv. I personally do not like system python distributions, especially from debian guys.
使用conda list
查看pip版本,确实更新为20.1,但是下面这个错误还是没有解决……
(torch) root@1c113923969c:/data/WWW# pip -V
Traceback (most recent call last):
File "/usr/bin/pip", line 11, in <module>
load_entry_point('pip==20.0.2', 'console_scripts', 'pip')()
File "/root/anaconda3/envs/torch/lib/python3.6/site-packages/pkg_resources/__init__.py", line 474, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/root/anaconda3/envs/torch/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2846, in load_entry_point
return ep.load()
File "/root/anaconda3/envs/torch/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2450, in load
return self.resolve()
File "/root/anaconda3/envs/torch/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2456, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 24, in <module>
from pip._internal.exceptions import CommandError
File "/usr/lib/python3/dist-packages/pip/_internal/exceptions.py", line 10, in <module>
from pip._vendor.six import iteritems
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 65, in <module>
vendored("cachecontrol")
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
__import__(modulename, globals(), locals(), level=0)
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/CacheControl-0.12.6-py2.py3-none-any.whl/cachecontrol/__init__.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/CacheControl-0.12.6-py2.py3-none-any.whl/cachecontrol/wrapper.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/CacheControl-0.12.6-py2.py3-none-any.whl/cachecontrol/adapter.py", line 5, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/requests-2.22.0-py2.py3-none-any.whl/requests/__init__.py", line 95, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl/urllib3/contrib/pyopenssl.py", line 46, in <module>
File "/root/anaconda3/envs/torch/lib/python3.6/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "/root/anaconda3/envs/torch/lib/python3.6/site-packages/OpenSSL/crypto.py", line 8, in <module>
from cryptography import utils, x509
File "/root/anaconda3/envs/torch/lib/python3.6/site-packages/cryptography/utils.py", line 11, in <module>
import typing
File "/root/anaconda3/envs/torch/lib/python3.6/site-packages/typing.py", line 1359, in <module>
class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
File "/root/anaconda3/envs/torch/lib/python3.6/site-packages/typing.py", line 1007, in __new__
self._abc_registry = extra._abc_registry
AttributeError: type object 'Callable' has no attribute '_abc_registry'
不过用轮子安装好了那个库,暂时可以正常使用了。
另一种安装方式:
python -m pip install pip==20.0.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
然后在MobaXterm里使用命令pip -V
查看pip
版本:
(torch) ╭─root@1c113923969c ~
╰─# pip -V
pip 20.0.2 from /root/anaconda3/envs/torch/lib/python3.6/site-packages/pip (python 3.6)
然而在VsCode远程服务器上仍然报错:
Traceback (most recent call last):
File "/root/anaconda3/envs/torch/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 28, in <module>
from pip._internal.models.target_python import TargetPython
File "/usr/lib/python3/dist-packages/pip/_internal/models/target_python.py", line 4, in <module>
from pip._internal.utils.misc import normalize_version_info
File "/usr/lib/python3/dist-packages/pip/_internal/utils/misc.py", line 23, in <module>
from pip._vendor.retrying import retry # type: ignore
ModuleNotFoundError: No module named 'pip._vendor.retrying'
2023年6月28日更新……
上面那两个错误简直是噩梦……今天又遇到这个问题了,pip怎么搞都弄不好,后来索性把原来的 python3.6 虚拟环境删除,重新创建了一个 python3.8 版本的虚拟环境,目前一切正常。猜测可能是 python3.6 版本太低,无法兼容 pip 最新版。
参考资料