33

I installed pip3 using sudo apt-get install python3-pip after that when I run the following command to install django sudo pip3 install django I get this error:

Traceback (most recent call last): File "/usr/bin/pip3", line 9, in from pip import main File "/usr/lib/python3/dist-packages/pip/init.py", line 14, in from pip.utils import get_installed_distributions, get_prog File "/usr/lib/python3/dist-packages/pip/utils/init.py", line 23, in from pip.locations import ( File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in from distutils import sysconfig ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/init.py)

How do I fix this?

2 Answers 2

75

I have tried recently manually installing python3.9 version in my Ubuntu from 3.6 version using apt install python3.9. Then pip3 was broken. The issue is because distutils were not build for the 3.9 version.

So in my case I ran apt install python3.9-distutils to resolve my issue.

In your case make sure to modify 3.x version in distutils command.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer it help me to resolve my issue
i.e. run sudo apt-get install python3.8-distutils
for me : sudo apt-get install python3.7-distutils worked also.
17

This helped but then I got another error: ImportError: No module named 'pip._internal'

The following fixed it:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

python3 get-pip.py --force-reinstall

1 Comment

I encountered a similar error on python 3.10 and could fix it with python3.10 -m ensurepip --upgrade

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.