Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'Iterable' from 'collections' #6184

Open
LingkKang opened this issue Jan 1, 2023 · 3 comments
Open

ImportError: cannot import name 'Iterable' from 'collections' #6184

LingkKang opened this issue Jan 1, 2023 · 3 comments

Comments

@LingkKang
Copy link

I am going through the coala tutorial, and run into a problem.

I cloned the coala-tutorial repo to my machine, and when I run command coala --files=src/\*.c --bears=SpaceConsistencyBear --save in the coala-tutorial directory, I got this error message:

[ERROR][21:11:49] An unknown error occurred. This is a bug. We are sorry for the inconvenience. Please contact the developers for assistance. During execution of coala an exception was raised. This should never happen. When asked for, the following information may help investigating:
[INFO][21:11:49] Exception was:
Traceback (most recent call last):

in <module>
    import readline  # pylint: disable=unused-import

  File "D:\Python3.10\lib\site-packages\readline.py", line 34, in <module>
    rl = Readline()

  File "D:\Python3.10\lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
    BaseReadline.__init__(self)

  File "D:\Python3.10\lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
    mode.init_editing_mode(None)

  File "D:\Python3.10\lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
    self._bind_key('space',       self.self_insert)

  File "D:\Python3.10\lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
    if not callable(func):

  File "D:\Python3.10\lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
    return isinstance(x, collections.Callable)

AttributeError: module 'collections' has no attribute 'Callable'

And similarly, when I run coala --files=src/\*.py --bears=PEP8Bear --save, I got:

[ERROR][21:14:05] An unknown error occurred. This is a bug. We are sorry for the inconvenience. Please contact the developers for assistance. During execution of coala an exception was raised. This should never happen. When asked for, the following information may help investigating:
[INFO][21:14:05] Exception was:
Traceback (most recent call last):

  File "D:\Python3.10\lib\site-packages\coalib\coala.py", line 35, in main
    from coalib.output.ConsoleInteraction import (

  File "D:\Python3.10\lib\site-packages\coalib\output\ConsoleInteraction.py", line 8, in <module>
    import readline  # pylint: disable=unused-import

  File "D:\Python3.10\lib\site-packages\readline.py", line 34, in <module>
    rl = Readline()

  File "D:\Python3.10\lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
    BaseReadline.__init__(self)

  File "D:\Python3.10\lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
    mode.init_editing_mode(None)

  File "D:\Python3.10\lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
    self._bind_key('space',       self.self_insert)

  File "D:\Python3.10\lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
    if not callable(func):

  File "D:\Python3.10\lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
    return isinstance(x, collections.Callable)

AttributeError: module 'collections' has no attribute 'Callable'

I'm not sure what's wrong with it. Did I ignore something important?

For your information, I installed coala with command pip install coala-bears, and other thing are as followed:

  • OS: Windows 10 Pro 21H2
  • Python: 3.10.2
  • pip: 21.2.4
  • coala: 0.11.0
  • coala-bears: 0.11.1
  • coala-utils: 0.6.7

As you may see, I didn't install python in default location, but I don't think this could be the reason.

Many thanks in advance.

@LingkKang
Copy link
Author

UPDATE

I found this blog and it said collections.Callable was moved into collections.abc.Callable since python 3.10 and above.

And I found there is a new maintained version of pyreadline, named as pyreadline3.

So I ran command pip install --upgrade pyreadline3, and ran coala --files=src/\*.c --bears=SpaceConsistencyBear --save again, surprisingly, error message reads like:

[ERROR][23:25:21] An unknown error occurred. This is a bug. We are sorry for the inconvenience. Please contact the developers for assistance. During execution of coala an exception was raised. This should never happen. When asked for, the following information may help investigating:
[INFO][23:25:21] Exception was:
Traceback (most recent call last):

  File "D:\Python3.10\lib\site-packages\coalib\coala.py", line 35, in main
    from coalib.output.ConsoleInteraction import (

  File "D:\Python3.10\lib\site-packages\coalib\output\ConsoleInteraction.py", line 13, in <module>
    from coalib.misc.DictUtilities import inverse_dicts

  File "D:\Python3.10\lib\site-packages\coalib\misc\DictUtilities.py", line 1, in <module>
    from collections import defaultdict, Iterable, OrderedDict

ImportError: cannot import name 'Iterable' from 'collections' (D:\Python3.10\lib\collections\__init__.py)

At least it got shorter. 🤷‍♂️

@LingkKang
Copy link
Author

From the python docs, collections.Iterable was moved to collections.abc.Iterable.

So maybe this is the reason why there is an ImportError.

from collections import defaultdict, Iterable, OrderedDict

@LingkKang LingkKang changed the title AttributeError: module 'collections' has no attribute 'Callable' ImportError: cannot import name 'Iterable' from 'collections' Jan 2, 2023
@PhilipDeegan
Copy link

Seeing this locally on python3.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants