No module named ‘pip._internal‘

问题描述

在项目编译过程中出现了错误导致编译中断, 错误提示具体如下:

Traceback (most recent call last):
  File "setup.py", line 219, in <module>
    if not is_installed('cython_bbox'):
  File "setup.py", line 177, in is_installed
    from pip._internal.utils.misc import get_installed_distributions
ModuleNotFoundError: No module named 'pip._internal'

然后在自己的python环境中尝试导入报错如下:

[Muyi@ai-research AlphaPose-master]$ python3
Python 3.6.2 (default, Nov 19 2019, 14:03:45) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pip._internal.utils.misc import get_installed_distributions
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/Muyi/Python/Package/python36/lib/python3.6/site-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/home/Muyi/Python/Package/python36/lib/python3.6/site-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/home/Muyi/Python/Package/python36/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
    @_call_aside
  File "/home/Muyi/Python/Package/python36/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
    f(*args, **kwargs)
  File "/home/Muyi/Python/Package/python36/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
    dist.activate(replace=False)
  File "/home/Muyi/Python/Package/python36/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
    declare_namespace(pkg)
  File "/home/Muyi/Python/Package/python36/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/home/Muyi/Python/Package/python36/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
  File "/home/Muyi/Python/Package/python36/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path
    orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'

解决方案

这意味着依赖关系混乱了,尝试了 pip3 install --upgrade setuptools 等一些方法,未能处理这个问题。
最后我通过重新安装 pip 解决了这个问题。

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值