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) 1 2 Answers
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-distutilsAnd 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.
4Answer(work in progress,collaboratively): upon review of the locations.py file referenced in the PyCharm error message('Failed to install package Kivy')
File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in <module> from distutils import sysconfig
(most recent traceback: 'ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.9/distutils/__init__.py)'at line 76 in locations.py, there is a block that reads as following:
# under macOS + virtualenv sys.prefix is not properly resolved
# it is something like /path/to/python/bin/..
# Note: using realpath due to tmp dirs on OSX being symlinks
src_prefix = os.path.abspath(src_prefix)
# FIXME doesn't account for venv linked to global site-packagesthis is an answer in progress but our problem seems to be referential to an inconsistent sys.prefix and/or src_prefix value defined by locations.py, troubleshooting and back-tracing now, will update shortly. Edit/update: at line 82 i believe is the problem,
# FIXME doesn't account for venv linked to global site-packagesbut a lot of this is over my head, i'm not equipped to re-write pip scripts at present. the distutils directory it's linking to '/usr/lib/python3.9/distutils/' is effectively empty, and missing most of the files it needs to carry through with the installation, but i'm unsure as of yet how to change the src_prefix value in-place to a better link to the working directory for python3, as distutils was deprecated post-3.2, i believe. linking to the base python3 install might be the best bet.