jim-easterbrook / Photini

An easy to use digital photograph metadata (Exif, IPTC, XMP) editing application.
https://photini.readthedocs.io/
GNU General Public License v3.0
155 stars 24 forks source link

Error ModuleNotFoundError: No module named 'cachetools.ttl' with cachetools >= 5.0 #244

Closed jlprojects closed 6 days ago

jlprojects commented 6 days ago

I really like photini for tagging my analogue photo scans.

Using OpenSuSE slowroll, Python 3.11 in a virtual environment. However installing as per ReadtheDocs I always get an error log on start, and the mapping tabs don't work. The error log is:

11:35:30: ERROR: photini.pyqt: No module named 'cachetools.ttl'
Traceback (most recent call last):
  File "/home/user/venv/lib64/python3.11/site-packages/photini/pyqt.py", line 190, in wrapper
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/user/venv/lib64/python3.11/site-packages/photini/editor.py", line 468, in add_tabs
    tab['object'] = tab['class'](self.app.image_list)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/venv/lib64/python3.11/site-packages/photini/photinimap.py", line 212, in __init__
    self.geocoder = self.get_geocoder()
                    ^^^^^^^^^^^^^^^^^^^
  File "/home/user/venv/lib64/python3.11/site-packages/photini/googlemap.py", line 102, in get_geocoder
    return GoogleGeocoder(parent=self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/venv/lib64/python3.11/site-packages/photini/photinimap.py", line 55, in __init__
    self.query_cache = pickle.load(f)
                       ^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'cachetools.ttl'

Pip currently brings in cachetools 5.3.3 - Googling the error doesn't seem to result any clues, but I did find a reference (which I didn't make a note of and can't find the link now, sorry) that indicates that cachetools.ttl was a hidden API, or deprecated.

Photini works correctly if I force Pip to install a version of cachetools < 5.0.0 - e.g.

pip install --force-reinstall -v "cachetools==4.2.4"

This works as a workaround - so posting here in case it helps anyone else.

jim-easterbrook commented 6 days ago

Thanks for reporting this.

I just tried this in a newly created Python 3.11 virtual environment on my openSUSE Leap 15.5 desktop machine and I'm not getting any problem with the map tabs.

$ python -m photini --version
No module named 'enchant'
No module named 'gpxpy'
Photini 2024.5.0
  Python 3.11.9 (main, Apr 18 2024, 16:44:43) [GCC]
  python-exiv2 0.16.3, exiv2 0.28.2
  PyQt 5.15.10, Qt 5.15.2
  system locale en-GB, locales: en-GB
  ffmpeg version 4.4.4 Copyright (c) 2000-2023 the FFmpeg developers
  styles: Windows, Fusion
  using style: fusion
$ pip list
Package            Version
------------------ --------
appdirs            1.4.4
cachetools         5.3.3
certifi            2024.6.2
chardet            5.2.0
charset-normalizer 3.3.2
exiv2              0.16.3
filetype           1.2.0
idna               3.7
Photini            2024.5.0
pillow             10.3.0
pip                24.1
PyQt5              5.15.10
PyQt5-Qt5          5.15.2
PyQt5-sip          12.13.0
PyQtWebEngine      5.15.6
PyQtWebEngine-Qt5  5.15.2
requests           2.32.3
setuptools         65.5.0
urllib3            2.2.2

I'll see if I can find anything in my use of cachetools that might be deprecated.

jim-easterbrook commented 6 days ago

The change log for cachetools shows the submodule ttl was removed in version 5.0.0, but Photini doesn't directly use cachetools.ttl so that shouldn't be a problem. https://github.com/tkem/cachetools/blob/master/CHANGELOG.rst

Photini started using cachetools in March 2022 and that bit of code hasn't changed since. This is all very mysterious.

jim-easterbrook commented 6 days ago

Aha! If I install an old version of cachetools, e.g. pip install "cachetools<4", then run Photini and do a map search, it creates a .pkl cache file that I assume refers to cachetools.ttl. Updating cachetools to v5.3.3 then gives me unloadable map tabs, but without the helpful error log you got.

Try deleting the .pkl files in ~/.cache/photini/, then update cachetools, then run Photini.

jlprojects commented 6 days ago

Bingo. Didn't know about the '.cache/photini '- looks like there are some very old things in there. Updating cachetools to 5.3.3 and deleting (renaming) '.cache/photini' everything works now.

Found the link to a issue mentioning cachetools.ttl: https://github.com/tkem/cachetools/issues/225#issuecomment-930974449 May not be relevant at all given this.

Thanks for your help with this.

jlprojects commented 6 days ago

I recall having problems when upgrading my system to OpenSuse 15.6 - but I'm unsure how I fixed it. Probably by using a system cachetools library - so that was the workaround then. Root cause looks an out of date bit of cruft in the .cache/photini folder.

Again thanks for a very useful piece of software and quick resolution. :+1:

jim-easterbrook commented 6 days ago

I've made the cache loading a bit more robust against errors like this. Thanks again for reporting the problem.

jlprojects commented 6 days ago

Thanks again. :smiley: