Upgrading versions of python causes dependencies to break - sequences in collections?

I use python through Jupyter notebooks to process data related to Earth and ocean science and I use this method to teach graduate students how to approach their data through code. I recently starting seeing messages in VS Code that stated my version of python, 3.9.7, will soon be out of date. To stay ahead of this, I downloaded version 3.13.

This upgrade in versions broke some code I had written using a module called rampedpyrox from PyPi. The module is called in one of the modules I wrote, so the error would occur when loading initial packages and would be assigned to my module that called rampedpyrox. The error generated is:

Cannot import name “Sequence” from “Collections”

I found a few entries of a similar questions on Stack Overflow (example), but they all seemed to have to do with python-flask and Azure App services, with have nothing to do with my code. But, through these answers, it seemed like something was missing in the new Python builds. I tried v3.12, and got the same error. Finally, I uninstalled all of the new versions and went back to 3.9.7.

So the questions I have are:

  1. How can these sorts of things be avoided/predicted without spending hours chasing down solutions when upgrading versions? Maybe that is unanswerable…
  2. Is this an error that needs to be fixed within the Python release, or within the module rampedpyrox that I was using? In either case, I don’t have control over the modules.
  3. If the cause of this error cannot be identified, is creation of a virtual environment with python 3.9.7 the only way to continue working with the rampedpyrox package as the python version is deprecated?

Thank you.

1 Like

Running Python 3.9 interactively:

Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from collections import Sequence
<stdin>:1: 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

Running Python 3.13 interactively:

Python 3.13.3 (tags/v3.13.3:6280bb5, Apr  8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from collections.abc import Sequence
1 Like

Avoid jumping so many Python versions at once. Watch for deprecation warnings. Check a package looks actively maintained before using it as a dependency. Keep banging the drum for Python not breaking backwards compatibility over trivial renames like this one.

Anywhere in rampedpyrox that says from collections import Sequence needs to be replaced with from collections.abc import Sequence. It’s open source. You can submit the fix yourself. Hopefully the project author is at least active enough to accept changes.

That’s not going to make any difference. Python 3.9 in a virtual environment is still Python 3.9 and is still just as deprecated.

3 Likes

Unfortunately there’s no surefire way. Python sometimes makes backwards-incompatible changes, which means that libraries have to be updated to keep working. If the libraries aren’t maintained, they’ll break, and then other libraries that depend on them may break, and so on.

For this specific problem, you can likely do a monkeypatch to temporarily fix things. In your code, before you import rampedpyrox, you could do this:

import collections
collections.Sequence = collections.abc.Sequence

This will add the name in the place rampedpyrox expects it to be.

I just tested this and it does let me successfully import rampedpyrox, but I can’t vouch for whether there are other incompatibilities that will only crop up when you actually try to use the library. That’s the problem with hacks like this: they may only half-work, or work for a while and then stop working due to some other change.

Unfortunately they apparently aren’t, since a pull request to fix this was submitted more than two years ago but is just in limbo. It might be necessary to fork the package.

3 Likes

Thank you @bwoodsend , and @BrenBarn . Your responses were quick and helpful! I have forked the repository, repaired the problem, and contacted the owner of the repository. I am looking to branch this fix into the original repository. I had actually contacted him about a year ago asking if it was OK to fork it, and he agreed, but I never got around to it. Nothing like broken code to provide a deadline!

Also thank you @MRAB - as a new poster, the system would only allow me to mention 2 users. Your example showed how simple the fix was.