Error "Attributeerror 'Collections' Has No Attribute 'Callable' " Using Beautiful Soup

I followed all steps to install Beautiful Soup, but it still comes out with this error:

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

I am using Python 3.10.

5

10 Answers

collections.Callable has been moved to collections.abc.Callable in python 3.10+. A hacky solution is to add the reference back to collections before importing the problem library.

import collections
collections.Callable = collections.abc.Callable

from bs4 import BeautifulSoup # for example
4

This solution worked for me:

  1. Navigate to Python310\Lib\site-packages\pyreadline in your file browser.
  2. Open py3k_compat.py in an text editor.
  3. Change the 8th line from which should be return isinstance(x, collections.Callable) to return isinstance(x, collections.abc.Callable).
  4. Save, exit and then retry.

I got the same AttributeError.

Then I looked inside the Python lib → collections folder. It has ABCs (abstract base classes) made separately in version 3.3 and above.

So resolve the error by opening /bs4/elements.py in an editor and replace collections.callable with collections.abc.callable. Hence the callable attribute can be easily accessed.

1

You can uninstall the Python package pyreadline and install pyreadline3, which is an updated fork !

1

Change "%LOCALAPPDATA%\Programs\Python\Python310\Lib\site-ackages\pyreadline\py3k_compat.py" - 8th code as below: return isinstance(x, collections.abc.Callable)

3

Beautiful Soup did not work with 3.10.

Reinstall with 3.9.

1

I was getting the same error while trying to run manticore, but apparently none of the answers were answering Mac users. So if you are on Mac and getting the same error, you have got to navigate to

lib/python3.10/site-packages/wasm/types.py Line 246

and change

isinstance(cur_field, collections.Callable) to isinstance(cur_field, collections.abc.Callable)

1

I had Beautiful Soup in a folder within the same folder as the Python program, as opposed to "installing" it.

So in that folder, I opened element.py and replaced all collections.Callable with collections.abc.Callable.

Python version 3.10.7

2

This error message indicates you have an old version of Beautiful Soup. The issue was already fixed back in Beautiful Soup 4.6.1, a release that came out in 2018. As of this writing, Beautiful Soup is up to version 4.11.1.

Update your Beautiful Soup, and the problem should be resolved.

instead of installing the zip folder of bs4, install it using your command prompt by typing: - pip install beautifulsoup4

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest