Please add a code sample or a nbviewer link, copy-pastable if possible
import folium
from tkinter import *
class UserInterface:
"""This is just a basic interface to enter coordinates to test the folium functionality"""
def __init__(self):
super(UserInterface,self).__init__()
UserInterface.window = Tk()
UserInterface.map_name_label = Label(UserInterface.window, text="Enter A Map Name")
UserInterface.map_name_label.grid(row=0, column=0)
UserInterface.map_name_text = StringVar()
UserInterface.map_name_entry = Entry(UserInterface.window, textvariable=UserInterface.map_name_text)
UserInterface.map_name_entry.grid(row=0, column=1)
UserInterface.lat1label = Label(UserInterface.window, text="Point 1 Lat:")
UserInterface.lat1label.grid(row=1, column=0)
UserInterface.lat1text = StringVar()
UserInterface.lat1_entry = Entry(UserInterface.window, textvariable=UserInterface.lat1text)
UserInterface.lat1_entry.grid(row=1, column=1)
UserInterface.long1label = Label(UserInterface.window, text="Point 1 Long:")
UserInterface.long1label.grid(row=2, column=0)
UserInterface.long1text = StringVar()
UserInterface.lat1_entry = Entry(UserInterface.window, textvariable=UserInterface.long1text)
UserInterface.lat1_entry.grid(row=2, column=1)
UserInterface.lat2label = Label(UserInterface.window, text="Point 2 Lat:")
UserInterface.lat2label.grid(row=3, column=0)
UserInterface.lat2text = StringVar()
UserInterface.lat2_entry = Entry(UserInterface.window, textvariable=UserInterface.lat2text)
UserInterface.lat2_entry.grid(row=3, column=1)
UserInterface.long2label = Label(UserInterface.window, text="Point 2 Long:")
UserInterface.long2label.grid(row=4, column=0)
UserInterface.long2text = StringVar()
UserInterface.long2_entry = Entry(UserInterface.window, textvariable=UserInterface.long2text)
UserInterface.long2_entry.grid(row=4, column=1)
UserInterface.create_map_button = Button(UserInterface.window, text="Get Map", command=UserInterface.get_map, width=20)
UserInterface.create_map_button.grid(row=5, columnspan=2)
UserInterface.map_status = Label(UserInterface.window, text="")
UserInterface.map_status.grid(row=6, column=0)
UserInterface.window.mainloop()
def get_map():
UserInterface.map_status = Label(UserInterface.window, text="Getting map...")
UserInterface.map_status.grid(row=6, column=0)
centerpoint = [float(UserInterface.lat1text.get()), float(UserInterface.long1text.get())]
marker = [float(UserInterface.lat2text.get()),float(UserInterface.long2text.get())]
MapProgram.mapping.create_map(centerpoint=centerpoint, marker=marker)
class FoliumTest:
"""This is just a basic class declaration to test the compiling process of folium when using Pyinstaller"""
def __init__(self):
super(FoliumTest,self).__init__()
def create_map(self, centerpoint, marker):
map_image = folium.Map(location=[centerpoint[0], centerpoint[1]], zoom_start=14, tiles='OpenStreetMap')
centerpoint_icon_url = "http://maps.google.com/mapfiles/kml/shapes/star.png"
centerpoint_icon = folium.features.CustomIcon(centerpoint_icon_url, icon_size=(70,70))
folium.Marker([centerpoint[0], centerpoint[1]], icon=centerpoint_icon).add_to(map_image)
custom_map_icon_url = "http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png"
custom_map_icon = folium.features.CustomIcon(custom_map_icon_url, icon_size=(50,50))
folium.Marker([marker[0], marker[1]], icon=custom_map_icon).add_to(map_image)
map_image.save(outfile=UserInterface.map_name_text.get() + ".html")
UserInterface.map_status = Label(UserInterface.window, text="Map created!")
UserInterface.map_status.grid(row=6, column=0)
class MapProgram:
"""This sets up the interface with the mapping functionality"""
def __init__(self):
MapProgram.mapping = FoliumTest()
UserInterface()
#Optional Coords to use for testing
#centerpoint = [37.9969,-121.2919]
#marker = [38.0132,-121.3671])
def main():
MapProgram()
if __name__ == '__main__':
main()
Problem description
When attempting to make an exe using pyinstaller, cx_freeze, py2exe etc, the folium module and its dependencies don't seem to get compiled properly so that the program can run successfully. In the process of trying to determine where the core problem resided, I came across unexpected behavior when typing from folium import *
which resulted in an error AttributeError: module 'folium' has no attribute 'GeoJsonStyle'
This seemed odd to me and I thought possibly why the exe is not being compiled as it would throw the error that _cnames.json
could not be found, which makes sense if GeoJsonStyle
doesn't exist in the module but perhaps it's supposed to. If I attempt to compile the above program, but comment out folium, the compiled executable runs fine, so I know it's related to folium specifically.
Expected Output
I expected the module to compile and load correctly so that it can be utilized in an executable.
Output of folium.__version__
0.7.0
question