vatlab / sos-notebook

Multi-language Jupyter Notebook
http://vatlab.github.io/SoS
BSD 3-Clause "New" or "Revised" License
176 stars 17 forks source link

ImportError: cannot import name 'Sized' from 'collections' #336

Closed andrewcrook closed 2 years ago

andrewcrook commented 2 years ago

Python 3.10, macOS 12, M1, Jupyter notebooks (6.4.8) Upon starting jupyter notebook failes to load kernel and loops looks like a import error

Traceback (most recent call last):
  File "/Users/andrew/.asdf/installs/python/3.10.1/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/andrew/.asdf/installs/python/3.10.1/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/andrew/code/Jupyter/.direnv/python-3.10.1/lib/python3.10/site-packages/sos_notebook/kernel.py", line 32, in <module>
    from .completer import SoS_Completer
  File "/Users/andrew/code/Jupyter/.direnv/python-3.10.1/lib/python3.10/site-packages/sos_notebook/completer.py", line 11, in <module>
    from .magics import SoS_Magics
  File "/Users/andrew/code/Jupyter/.direnv/python-3.10.1/lib/python3.10/site-packages/sos_notebook/magics.py", line 11, in <module>
    from collections import Sized, OrderedDict, Sequence
ImportError: cannot import name 'Sized' from 'collections' (/Users/andrew/.asdf/installs/python/3.10.1/lib/python3.10/collections/__init__.py)
andrewcrook commented 2 years ago

I am fixing right now

andrewcrook commented 2 years ago

Pull request #337

Replaced collections imports with collections.abc for Sized, Sequence otherwise causes ImportError Changed in Python 3.3. Old method stops working in python 3.10

https://stackoverflow.com/a/70195883

BoPeng commented 2 years ago

Thanks. I have not tried 3.10 yet so I have not noticed this problem.

I have merged the PR and will check if there is any pending bug that prevents a new release.

andrewcrook commented 2 years ago

@BoPeng Thank you

FYI I removed the following notice

Please Note: collections.abc does not work for OrderedDict still have to use collections I think this need to be raised as a python issue.

Because looking at python documentation I believe this is correct collections.abc has been taken out from collections and contains the Abstract Base Classes for Containers (hence abc) whilst the other classes (specialised container datatypes providing alternatives to Python’s general purpose built-in containers), remain in collections.