Python3 pip3在Ubuntu上安装失败


14

我在Ubuntu16.04上成功安装了python3和pip3,但pip3的安装已损坏。我该如何解决这个问题?的错误信息pip3 install如下:

# pip3 install xlwt
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
  from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 21, in <module>
  from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
ModuleNotFoundError: No module named 'pip._vendor.requests'

输出 sudo -H pip3 install --upgrade pip

sudo -H pip3 install --upgrade pip  
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
  from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 21, in <module>
  from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
ModuleNotFoundError: No module named 'pip._vendor.requests'

which pip3和的输出pip3 --version

# which pip3
/usr/bin/pip3

# pip3 --version
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 21, in <module>
    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
ModuleNotFoundError: No module named 'pip._vendor.requests'

PS Python2 pip成功运行。输出“哪个pip”和“ pip --version”:

# which pip
/usr/bin/pip

# pip --version
pip 1.5.4 from /usr/local/lib/python2.7/dist-packages/pip-1.5.4-py2.7.egg (python 2.7)

以及python和python3的安装信息:

# which python
/usr/bin/python
# which python3
/usr/bin/python3

# python -V
Python 2.7.14
# python3 -V
Python 3.6.3  

您在帖子中说了16.04,但使用了14.04标签。哪个版本正确?
edwinksl

1
16.04是正确的。我现在找不到16.04标签。抱歉。
mlpy

Answers:


12

pip3出了点问题,请删除并重新安装。打开终端并输入:

sudo apt purge python3-pip  
sudo rm -rf '/usr/lib/python3/dist-packages/pip'  
sudo apt install python3-pip   
cd
cd .local/lib/python3/site-packages
sudo rm -rf pip*  
cd
cd .local/lib/python3.5/site-packages
sudo rm -rf pip*  
python3 -m pip install --user xlwt

3
我尝试过但仍然是相同的错误:imgur.com/a/nAdqU
mlpy

我尝试了新的解决方案,但仍然是相同的错误。
mlpy

我也有同样的问题。这样做时sudo apt install python3-pip,出现以下错误:The following packages have unmet dependencies: python3-pip : Depends: python-pip-whl (= 8.1.1-2) but 8.1.1-2ubuntu0.4 is to be installed Recommends: build-essential but it is not going to be installed Recommends: python3-dev (>= 3.2) but it is not going to be installed Recommends: python3-wheel but it is not going to be installed E: Unable to correct problems, you have held broken packages.
Kristada673 '18

@ Kristada673尝试阅读以下问题的答案:askubuntu.com/questions/363200/…。DragonLord的答案对我有用。
karel

6

安装python3-pip软件包在/ usr / bin / pip3文件中创建一个python脚本。为了运行,需要从模块pip(from pip import main)中导入main()函数。此方法路径仅适用于打包的pip版本(在我的情况下为9.0.1)。

运行后pip3 install --upgrade pip,pip版本变为18.1,并且main()已移入pip._internal

使用命令python3 -m pip --version查看您的情况是否对应于相同情况(断点时,pip3也可通过此方法使用/usr/bin/pip3)。

如果是这样,请在文件/ usr / bin / pip3中,将第9行 from pip import mainfrom pip._internal import main

该问题将得到解决。(在Ubuntu 18.04发行版上测试)


更改导入后,出现了另一个错误File "/usr/bin/pip3", line 11, in <module> sys.exit(main()) TypeError: 'module' object is not callable
Miranda

2

这是我发现有帮助的:

  1. sudo rm -rf /usr/local/lib/python3.5/dist-packages
  2. 千万不要在pip3里面跑sudo

虽然这可能会解决问题,但您能否请您扩展答案?为什么这个目录中删除(可能添加有关告诫python3.5路径),为什么从来没有使用sudo ..上运行它,等等
罗伯特·里德尔

我在这方面不是一个专家-我只是想分享对我有用的东西。
Jan Lachnitt '18 Jan 29'23


1

首先删除损坏的pip3:

rm /user/bin/pip3 /user/local/bin/pip3

重新安装新的:

sudo apt-get remove python3-pip
sudo apt-get install python3-pip


0

正如@Vincent H.提到的那样,我遇到了同样的问题。

追溯(最近一次通话最近):文件“ /home/ashish/.local/bin/pip3”,行7,来自pip._internal导入主文件ImportError:没有名为“ pip._internal”的模块

此修复程序的问题是,以取代pip._internalpip.local/bin/pip3sudo gedit .local/bin/pip3


0

这是一个问题,但您可以解决。

rm /user/bin/pip3 /user/local/bin/pip
sudo apt-get remove python-pip

比重新安装

sudo apt-get install python-pip
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.