gmaps icon indicating copy to clipboard operation
gmaps copied to clipboard

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

Open rogeriobiondi opened this issue 4 years ago • 1 comments

Hello,

I'm trying to run the example from the documentation:

import gmaps
gmaps.configure(api_key='KEY...')
nuclear_power_plants = [
{'name': 'Atucha', 'location': (-34.0, -59.167), 'active_reactors': 1},
{'name': 'Embalse', 'location': (-32.2333, -64.4333), 'active_reactors': 1},
{'name': 'Armenia', 'location': (40.167, 44.133), 'active_reactors': 1},
{'name': 'Br', 'location': (51.217, 5.083), 'active_reactors': 1},
{'name': 'Doel', 'location': (51.333, 4.25), 'active_reactors': 4},
{'name': 'Tihange', 'location': (50.517, 5.283), 'active_reactors': 3}
]
plant_locations = [plant['location'] for plant in nuclear_power_plants]
info_box_template = "<dl><dt>Name</dt><dd>{name}</dd><dt>Number reactors</dt><dd>{active_reactors}</dd></dl>"
plant_info = [info_box_template.format(**plant) for plant in nuclear_power_plants]
marker_layer = gmaps.marker_layer(plant_locations, info_box_content=plant_info)
fig = gmaps.figure()
fig.add_layer(marker_layer)

But receiving the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [11], in <cell line: 14>()
     12 info_box_template = "<dl><dt>Name</dt><dd>{name}</dd><dt>Number reactors</dt><dd>{active_reactors}</dd></dl>"
     13 plant_info = [info_box_template.format(**plant) for plant in nuclear_power_plants]
---> 14 marker_layer = gmaps.marker_layer(plant_locations, info_box_content=plant_info)

File ~/.pyenv/versions/3.10.4/envs/teste/lib/python3.10/site-packages/gmaps/marker.py:553, in marker_layer(locations, hover_text, label, info_box_content, display_info_box)
    485 @doc_subst(_doc_snippets)
    486 def marker_layer(
    487         locations, hover_text='', label='',
    488         info_box_content=None, display_info_box=None):
    489     """
    490     Marker layer
    491 
   (...)
    551         A :class:`gmaps.Markers` instance.
    552     """
--> 553     marker_options = _marker_layer_options(
    554         locations, hover_text, label, info_box_content, display_info_box)
    555     markers = [Marker(**option) for option in marker_options]
    556     return Markers(markers=markers)

File ~/.pyenv/versions/3.10.4/envs/teste/lib/python3.10/site-packages/gmaps/marker.py:311, in _marker_layer_options(locations, hover_text, label, info_box_content, display_info_box)
    309 if is_atomic(label):
    310     label = [label] * number_markers
--> 311 if is_atomic(info_box_content):
    312     info_box_content = [info_box_content] * number_markers
    314 marker_options = {
    315     'location': locations_to_list(locations),
    316     'hover_text': hover_text,
    317     'label': label
    318 }

File ~/.pyenv/versions/3.10.4/envs/teste/lib/python3.10/site-packages/gmaps/options.py:40, in is_atomic(elem)
     34 def is_atomic(elem):
     35     """
     36     True if an element is a single atom and false if it's a collection
     37     """
     38     return (
     39         isinstance(elem, string_types) or
---> 40         not isinstance(elem, collections.Iterable)
     41     )

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

I'm using the latest gmaps library version 0.9.0 and Python 3.10.4.

Thanks

rogeriobiondi avatar Apr 22 '22 17:04 rogeriobiondi

Hi @rogeriobiondi, collections.Iterable has been deprecated and now it is in collections.abc.Iterable. Either you substitute collections.Iterable in the source code of the library or you should use a less recent version of python, I would say <= 3.7

AlexRossiATF avatar Apr 28 '22 12:04 AlexRossiATF