Python – Fix Python3 Pip3 Install Issues on Ubuntu

16.04pippythonpython-2.7python3

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  

Best Answer

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*  
python3 -m pip install xlwt
Related Question