Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)

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?

like image 586
Leman Kirme Avatar asked Sep 10 '20 06:09

Leman Kirme


2 Answers

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.

like image 172
Srinivas Batchu Avatar answered Nov 05 '22 09:11

Srinivas Batchu


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

like image 15
Felix Mueller Avatar answered Nov 05 '22 09:11

Felix Mueller