Python3 pip3 install broken on Ubuntu

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

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)


This is what I've found helpful:

  1. sudo rm -rf /usr/local/lib/python3.5/dist-packages
  2. Never run pip3 within sudo.