Search code examples
pythonfolium

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


I've been using Folium, tried versions 0.5.0 and 0.11.0, in a Python notebook in IBM Watson studio. folium.Map and folium.Circlemarker work fine, but folium.Rectangle fails... is there a way around this? Or is the function for adding a rectangle different now? Code that generated error in title is below

folium.Rectangle(bounds=[[39.78,-105.05],[39.68,-105.05],[39.68,-104.94],[39.78,-104.94]], color='#ff7800', fill=True, fill_color='#ffff00', fill_opacity=0.2).add_to(mapD)

Solution

  • At first, please double check your folium version using folium.__version__. (in python)

    According to changelog, you can use folium.CircleMarker after 0.4.0.

    0.4.0

    • PolyLine, Circle and CircleMarker are set to leaflet's defaults and accepted all Path's optional arguments (ocefpaf #683 and #697)

    Similarly, you can use folium.Rectangle only after 0.6.0.

    0.6.0

    • Rectangle and Polygon were renamed and set to leaflet's defaults. Both now accepted all Path's optional arguments (ocefpaf #722)

    So if your folium version is lower than 0.6.0, you should use folium.features.RectangleMarker instead of folium.Rectangle.

    If your folium version is really 0.11.0, but you cannot use folium.Rectangle still, please check if you correctly imported folium. (using import folium)