Migration from Python 3.8 to 3.11.5 is failing

I am facing issues while migrating from Python 3.8 to 3.11.5/3.12.8. Receiving “ImportError: cannot import name ‘Hashable’ from ‘collections’ (/usr/lib64/python3.11/collections/init.py)” error.
We are using python docker image to host onto redhat openshift.
Can anyone please help on how can we fix this issue. Do I need to change the code to be compatible with 3.11/3.12?

When you do from collections import Hashable in 3.8, you get this warning:

DeprecationWarning: Using or importing the ABCs from ‘collections’ instead of from ‘collections.abc’ is deprecated since Python 3.3, and in 3.10 it will stop working

Have you tried doing what the warning tells you?

I think you’ll need to import like this:

from collections.abc import Hashable

Until Python 3.9 it would have been:

from collections import Hashable

I tried with from collections.abc import Hashable in the code, but it dint work, still gives same error.

Unlikely. Post the exact code that is failing, along with the exact error message, and the Python version you are using.

1 Like

I am using python version 3.12.8. verified the code again, but there are no explicit imports for collection package. tried adding collection.abc import hashable in the code, but no luck.

The error message tells you which part of your code triggered it.

Post the complete error message.

1 Like