Search code examples
pythonpython-imaging-librarylinux-mintcinnamon

Linux Mint Cinnamon error opening settings (No module named 'PIL')


since I updated Cinnamon to 5.0.6 I can't access any entry under 'Preferences', nothing happens. When I try to open from CLI I have the following :

#> cinnamon-settings
No module named 'PIL'

I searched a lot but nothing suits my problem. I understand that it's a problem with Python and PIL module or the newer module Pillow but none of the solutions provided works for me.

Some informations :


#> python --version
Python 3.8.10

#> /usr/bin/env python
Python 3.8.10 (default, Sep 28 2021, 16:10:42) 

#> pip -V
pip 21.3 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)

#> pip show Pillow
Name: Pillow
Version: 8.4.0
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (PIL Fork Author)
Author-email: aclark@python-pillow.org
License: HPND
Location: /home/xxx/.local/lib/python3.8/site-packages
Requires: 
Required-by: image, imageio, img2pdf, matplotlib, ocrmypdf, pikepdf, reportlab, scikit-image


Do you have any ideas ?

Thanks

EDIT : I found this on the Cinnamon 5.0.6 changelog, I think this is the problem

  • cinnamon-settings: Remove ~/.local and /usr/local from python's module search paths

Solution

  • I found a workaround, reverting a change made in 5.0.6

    In the file /usr/share/cinnamon/cinnamon-settings/util.py I commented lines 9 and 10 :

    #!/usr/bin/python3
    
    def strip_syspath_locals():
        import sys
        import os
    
        new_path = []
        for path in sys.path:
            if path.startswith(("/usr/local", os.path.expanduser("~/.local"))):
                continue
            new_path.append(path)
    
        sys.path = new_path
    

    to

    #!/usr/bin/python3
    
    def strip_syspath_locals():
        import sys
        import os
    
        new_path = []
        for path in sys.path:
            # if path.startswith(("/usr/local", os.path.expanduser("~/.local"))):
            #    continue
            new_path.append(path)
    
        sys.path = new_path
    

    This may not be the best way to fix this problem, but it worked.

    Do you see a better solution or is it a bug in Cinnamon ?