Whenever I am trying to install any package using pip, I am getting this import error:

guru@guru-notebook:~$ pip3 install numpy
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'


guru@guru-notebook:~$ cat `which pip3`
#!/usr/bin/python3
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
    sys.exit(main())

It was working fine earlier, I am not sure why it is throwing this error. I have searched about this error, but can't find anything to fix it.

Please let me know if you need any further detail, I will update my question.

推荐答案

You must have inadvertently upgraded your system pip (probably through something like sudo pip install pip --upgrade)

pip 10.x adjusts where its internals are situated. The pip3 command you're seeing is one provided by your package maintainer (presumably debian based here?) and is not a file managed by pip.

You can read more about this on pip's issue tracker

You'll probably want to not upgrade your system pip and instead use a virtualenv.

To recover the pip3 binary you'll need to sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall.

If you want to continue in "unsupported territory" (upgrading a system package outside of the system package manager), you can probably get away with python3 -m pip ... instead of pip3.

Python相关问答推荐

运行回文查找器代码时发生错误:[类型错误:builtin_index_or_system对象不可订阅]

ModuleNotFound错误:没有名为Crypto Windows 11、Python 3.11.6的模块

可变参数数量的重载类型(args或kwargs)

pandas滚动和窗口中有效观察的最大数量

为什么这个带有List输入的简单numba函数这么慢

有没有一种方法可以从python的pussompy比较结果中提取文本?

如果条件不满足,我如何获得掩码的第一个索引并获得None?

在np数组上实现无重叠的二维滑动窗口

组/群集按字符串中的子字符串或子字符串中的字符串轮询数据框

pandas:排序多级列

连接一个rabrame和另一个1d rabrame不是问题,但当使用[...]'运算符会产生不同的结果

在Python中,从给定范围内的数组中提取索引组列表的更有效方法

Python中的变量每次增加超过1

重置PD帧中的值

Flask运行时无法在Python中打印到控制台

Cython无法识别Numpy类型

每次查询的流通股数量

在不中断格式的情况下在文件的特定部分插入XML标签

Sknowled线性回归()不需要迭代和学习率作为参数

`Convert_time_zone`函数用于根据为极点中的每一行指定的时区检索值