I updated python to python3.9, and when I try to install pip, I get an error:

lors@Lenovo:~$ pip3 install pipenv
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 29, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in <module>
    from pip.locations import (
  File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in <module>
    from distutils import sysconfig
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.9/distutils/__init__.py)
  • I have the same problem on Ubuntu 18.04 having installed Python 3.9 off the deadsnakes PPA – Pankrates Dec 2 '20 at 13:19

I am assuming you did changed update-alternatives for python3. What is happening that you have distutils installed in your last python version, but not in the new one! And because you've changed system link with "update-alternatives", system no longer finds it with the new link of python3. To fix this you have to install distutils to python3.9.

sudo apt install python3.9-distutils

And then you can test it with following line written in terminal:

python3 -c "from distutils import sysconfig"

If there is no Traceback you are good to go.

  • thanks for your answer, but i reinstall my linux – Dire_straits Dec 4 '20 at 0:08
  • In future avoid changing system links. Why I recommend this? You will have less headaches if you are new to linux. Better for you just use /path/to/python. Be extremely careful using update-alternatives. – Pr0ph3t_sec Dec 6 '20 at 17:54
  • thank for your attention dude, i dont have idea how i got this error and yes i am new in linux;) – Dire_straits Dec 7 '20 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.