Upgraded python to 3.9 on Ubuntu 20.04 and now certain packages don't work

Question:

I was using Python 3.8, and needed to upgrade to Python 3.9. I installed, and set the default to Python 3.9.

user@user-desktop:/usr/lib$ python3 --version
Python 3.9.5

I’m trying to import matplotlib, but it’s giving me this error:

usr@user-desktop:/usr/lib$ python3
Python 3.9.5 (default, Nov 23 2021, 15:27:38) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.9/site-packages/matplotlib/__init__.py", line 113, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "/home/user/.local/lib/python3.9/site-packages/matplotlib/rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "/home/user/.local/lib/python3.9/site-packages/matplotlib/colors.py", line 51, in <module>
    from PIL import Image
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 69, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)

I’ve tried the following:

user@user-desktop:/usr/bin$ pip uninstall PIL
WARNING: Skipping PIL as it is not installed.
user@user-desktop:/usr/bin$ pip uninstall Pillow
Found existing installation: Pillow 7.0.0
Not uninstalling pillow at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'Pillow'. No files were found to uninstall.

I tried installing them, since they weren’t there.

user@user-desktop:/usr/bin$ pip install PIL
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL
user@user-desktop:/usr/bin$ pip install Pillow
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (7.0.0)

I tried the same with pip3, and python -m pip and no luck.

From some other StackOverflow posts, I’ve set a static link between python3.9 and python3 by doing:

sudo ln -s python3.9 /usr/bin/python3

but I’m not sure that worked, taking a look at usr/bin/python:

user@user-desktop:/usr/bin$ ls -l python*
lrwxrwxrwx 1 root root      25 Sep  8 06:24 python3 -> /etc/alternatives/python3
-rwxr-xr-x 1 root root 5494584 Nov 14 07:59 python3.8
lrwxrwxrwx 1 root root      33 Nov 14 07:59 python3.8-config -> x86_64-linux-gnu-python3.8-config
-rwxr-xr-x 1 root root 5803968 Nov 23  2021 python3.9
lrwxrwxrwx 1 root root      16 Mar 13  2020 python3-config -> python3.8-config
-rwxr-xr-x 1 root root     384 Mar 27  2020 python3-futurize
-rwxr-xr-x 1 root root     388 Mar 27  2020 python3-pasteurize

When I use python3.8, I can install all of these modules just fine. Any help?

Asked By: stochasticlover1

||

Answers:

For others who had this issue, all I needed to do was upgrade Pillow using
python3.9 -m pip install Pillow --upgrade.

Answered By: stochasticlover1