简体   繁体   中英

Python3 pip3 install broken on Ubuntu

I installed python3 and pip3 successfully on my Ubuntu16.04, but pip3 install is broken. How can I fix this problem? The error info 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 "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'

ps 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

Any solution or clue will be appreciated! Thank you!

在这里,尝试这个方法: https : //pip.pypa.io/en/stable/installing/#installing-with-get-pip-py

# sudo python3 get-pip.py

This has happened to me multiple times before. A lot of the time, pip3 has issues installing with python3 by default, so try uninstalling and reinstalling pip3. Hope this works.

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

EDIT : After doing some scouting about pip.vendor.requests, it seems like this is a very common error relating to SSL problems. If this line gives you errors in python ( import ssl ), some solutions can be found here: https://github.com/pypa/pip/issues/2345 .

This worked for me.

First remove your python3-pip:

sudo apt remove python3-pip

Then do this:

sudo apt install --purge python3-setuptools

And finally:

sudo apt install python3-pip

python-pip is in the universe repositories, therefore use the steps below to solve Python3 pip3 broken problem on Ubuntu. Also works for Ubuntu available from official store in windows 10 for WSL (windows subsystem for linux):

sudo apt-get install software-properties-common
sudo apt-add-repository universe
sudo apt-get update
sudo apt-get -y install python3-pip 

I got help from here - [ https://askubuntu.com/a/672836/876942] . Following these steps installs python 2. But then I installed python 3 using [sudo apt-get -y install python3-pip] in last step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM