5

I installed python3 and pip3 successfully on my Ubuntu16.04, but pip3 install is broken. How can I fix this problem? The error information of pip3 install is as follows:

# 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'

Output of 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'

Output of which pip3 and 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'

P.S. Python2 pip runs successfully. Output of "which pip" and "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)

And python and python3 installation information:

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

# python -V
Python 2.7.14
# python3 -V
Python 3.6.3  
  • You said 16.04 in your post but used the 14.04 tag. Which version is correct? – edwinksl Oct 26 '17 at 11:21
  • 1
    16.04 is correct. I couldn't find the 16.04 tag just now. Sorry. – mlpy Oct 26 '17 at 11:28
5

There is something wrong with your pip3 so remove it and reinstall it. Open the terminal and type:

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*  
sudo pip3 install xlwt
  • 1
    I tried but still the same error: imgur.com/a/nAdqU . – mlpy Oct 26 '17 at 15:21
  • I tried the new solution but still the same error. – mlpy Oct 27 '17 at 5:44
  • I am having the same issue too. When I do sudo apt install python3-pip, I get the following error: 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 Jan 16 '18 at 8:07
  • @Kristada673 Try reading the answers to this question: askubuntu.com/questions/363200/…. DragonLord's answer worked for me. – karel Jan 16 '18 at 8:10
2

Installing python3-pip package create a python script in file /usr/bin/pip3. In order to run, main() function need to be imported from module pip (from pip import main). This method path is only available for packaged pip version (9.0.1 in my case).

After running pip3 install --upgrade pip, pip version become 18.1, and main() has been moved in pip._internal.

Use the command python3 -m pip --version to see if your case correspond to the same situation (pip3 is also available with this method when /usr/bin/pip3 is broken).

If so, in file /usr/bin/pip3, replace line 9: from pip import main with: from pip._internal import main

The issue will be fixed. (Tested on Ubuntu 18.04 distribution)

1

This is what I've found helpful:

  1. sudo rm -rf /usr/local/lib/python3.5/dist-packages
  2. Never run pip3 within sudo.
  • While that maybe fixes things, can you please expand your answer ? Why to remove this directory (maybe add a caveat about the python3.5 path), why never to run it with sudo, and so on.. – Robert Riedl Jan 22 '18 at 15:17
  • I am not quite an expert on this - I just wanted to share what had worked for me. – Jan Lachnitt Jan 29 '18 at 23:19
0

Had same issue, installing openssl fixed it for me

  • But openssl already install on my Ubuntu: imgur.com/a/60kIM . Maybe it's caused by another reason. – mlpy Oct 26 '17 at 12:56
0

As @Vincent H. mentioned, i encountered the same issue.

Traceback (most recent call last): File "/home/ashish/.local/bin/pip3", line 7, in from pip._internal import main ImportError: No module named 'pip._internal'

The fix to the issue was to replace pip._internal to pip in .local/bin/pip3 by doing sudo gedit .local/bin/pip3.

New contributor
TheLazy is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.