Folium: AttributeError- 'MarkerCluster'

Created on 5 Aug 2018  路  7Comments  路  Source: python-visualization/folium

Please add a code sample or a nbviewer link, copy-pastable if possible

# Your code here
map2 = folium.Map(location=[53.232350, -1.422151], tiles='CartoDB dark_matter', zoom_start=11)

marker_cluster = folium.MarkerCluster().add_to(map2)

for point in range(0, len(locationlist)):
    folium.Marker(locationlist[point], popup=df_counters['Name'][point]).add_to(marker_cluster)
map2

Problem description

When I try to run the above code, I get the following error.
[this should explain why the current behavior is a problem and what is the expected output.]

Expected Output

Output of folium.__version__

AttributeError Traceback (most recent call last)
in ()
6 map2 = folium.Map(location=[53.232350, -1.422151], tiles='CartoDB dark_matter', zoom_start=11)
7
----> 8 marker_cluster = folium.MarkerCluster().add_to(map2)
9
10 for point in range(0, len(locationlist)):

AttributeError: module 'folium' has no attribute 'MarkerCluster'

Most helpful comment

To clarify, MarkerCluster is a plugin and is not available in the main folium module. So you cannot use it as folium.MarkerCluster. Instead you have to import the plugins and get it from there. Two options:

import folium.plugins
folium.plugins.MarkerCluster()

or

from folium.plugins import MarkerCluster
MarkerCluster()

I'm closing the issue. Feel free to add comments with additional questions of info. We can reopen the issue if needed.

All 7 comments

You seem not to have imported the plugins module:

from folium.plugins import MarkerCluster

To clarify, MarkerCluster is a plugin and is not available in the main folium module. So you cannot use it as folium.MarkerCluster. Instead you have to import the plugins and get it from there. Two options:

import folium.plugins
folium.plugins.MarkerCluster()

or

from folium.plugins import MarkerCluster
MarkerCluster()

I'm closing the issue. Feel free to add comments with additional questions of info. We can reopen the issue if needed.

hi @Conengmo ! I have imported the plugins but I keep receiving the following message:
"Exception has occurred: AttributeError
module 'folium' has no attribute 'MarkerCluster'"

appreciate your help!

Can you share a code snippet?

Can you share a code snippet?

Thank you for your help, but I just solved the problem!

Also, I need to say that your Github's files have been very helpful! I am just a beginner with Python, and I have found a lot of useful info in your account and your comments. Thank you so much!

@barbaramchd good to hear you solved it, and thanks for the kind words :)

@barbaramchd Hola, C贸mo lo resolviste???

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wangchenwc picture wangchenwc  路  18Comments

ElmWer picture ElmWer  路  24Comments

agravier picture agravier  路  26Comments

achourasia picture achourasia  路  19Comments

olibchr picture olibchr  路  19Comments