danilobellini / audiolazy

Expressive Digital Signal Processing (DSP) package for Python
GNU General Public License v3.0
688 stars 74 forks source link

Support for newer python versions (> 3.7) #15

Open bytesnake opened 1 year ago

bytesnake commented 1 year ago

Bumping the python version from 3.6 fails because of a missing import from the collections library:

ImportError                               Traceback (most recent call last)
Cell In [2], line 7
      5 from scipy import signal
      6 import IPython.display as ipd
----> 7 from audiolazy import levinson_durbin
      8 import speech_test
      9 get_ipython().run_line_magic('matplotlib', 'inline')

File /opt/conda/lib/python3.10/site-packages/audiolazy/__init__.py:67
     16 """
     17 AudioLazy package
     18 
   (...)
     61 under the terms of the GPLv3.
     62 """
     64 # Some dunders and summary docstrings initialization
     65 __modules__, __all__, __doc__ = \
     66   __import__(__name__ + "._internals", fromlist=[__name__]
---> 67             ).init_package(__path__, __name__, __doc__)
     69 # Import all modules contents to the main namespace
     70 exec(("from .{} import *\n" * len(__modules__)).format(*__modules__))

File /opt/conda/lib/python3.10/site-packages/audiolazy/_internals.py:117, in init_package(package_path, package_name, docstring)
    102 """
    103 Package initialization, to be called only by ``__init__.py``.
    104 
   (...)
    114 used by the package to import every module into the main package namespace.
    115 """
    116 module_names = get_module_names(package_path)
--> 117 modules = get_modules(package_name, module_names)
    118 dunder_all = dunder_all_concat(modules)
    119 for module in modules:

File /opt/conda/lib/python3.10/site-packages/audiolazy/_internals.py:59, in get_modules(package_name, module_names)
     57 def get_module(name):
     58   return __import__(".".join([package_name, name]), fromlist=[package_name])
---> 59 return [get_module(name) for name in module_names]

File /opt/conda/lib/python3.10/site-packages/audiolazy/_internals.py:59, in <listcomp>(.0)
     57 def get_module(name):
     58   return __import__(".".join([package_name, name]), fromlist=[package_name])
---> 59 return [get_module(name) for name in module_names]

File /opt/conda/lib/python3.10/site-packages/audiolazy/_internals.py:58, in get_modules.<locals>.get_module(name)
     57 def get_module(name):
---> 58   return __import__(".".join([package_name, name]), fromlist=[package_name])

File /opt/conda/lib/python3.10/site-packages/audiolazy/lazy_analysis.py:23
     20 from __future__ import division
     22 from math import sin, cos, pi
---> 23 from collections import deque, Sequence, Iterable
     24 from functools import wraps, reduce
     25 from itertools import chain

ImportError: cannot import name 'Sequence' from 'collections' (/opt/conda/lib/python3.10/collections/__init__.py)
nils-werner commented 1 year ago

The solution is simple, import collections.abc.Sequence instead. It was introduced in Python 3.5.

Danielavillagran commented 4 months ago

The solution is simple, import collections.abc.Sequence instead. It was introduced in Python 3.5.

Hello! Got the same problem here! Wrote ‘from collections.abc import Sequence’ but problem persists. Did I miss something?

huappy commented 1 month ago

The solution is simple, import collections.abc.Sequence instead. It was introduced in Python 3.5.

Hello! Got the same problem here! Wrote ‘from collections.abc import Sequence’ but problem persists. Did I miss something?

Yes, you would need to update it for every file hat uses the Collections library to import sequence and any other component that got moved to Collections.abc, such as Sequence, Iterable, and Iterator. There should be a total of about 7 different files in the AudioLazy project that have the same issue. Also note, not everything that is getting imported from Collections is from Collections.abc, so you'll have to have to separate those imports. I attached an image showing you what I mean. All of the tabs at the top are all of the files that you're going to need to change.

If you change them one at a time, you can keep running the program finding the next import that you need to change from the error line.

Hope this helps!

image