question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Folium doesn't package as expected when compiling to an executable

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:32 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
nathan3leafcommented, Mar 7, 2019

@FabeG Well I can’t thank you enough for your patience and knowledge. My executable is FINALLY running when using folium. I’ve had to comment it out for months because I could never get it to run correctly, so this is actually a pretty big deal to me. Thanks so much!

1reaction
FabeGcommented, Mar 7, 2019

Hi @nathan3leaf, No problem for me to build an exe using folium with cx_freeze. Could you copy/paste the setup.py file you are using in order to find out what’s going wrong ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting error when converting python to exe (because of ...
html file using Folium module. As expected, the code doesn't return any error. import folium m = folium.Map(location=[39.3999, ...
Read more >
Folium 0.12.1 documentation
folium builds on the data wrangling strengths of the Python ecosystem and the mapping strengths of the leaflet.js library. Manipulate your data in...
Read more >
Custom heatmap with folium - Google Groups
So i was trying to use PyQt5 method to create an popup but GC doesn't load the python3.dll (on windows), Ale or someone...
Read more >
[Example code]-Folium library error in choropleth
Am using folium library with an open data set from kaggle, map.choropleth(geo_path=country_geo, data=plot_data, columns=['CountryCode', 'Value'], ...
Read more >
RemoteSensingTutorial
Jupyter Notebooks are executable notebooks which allow us to document and run ... in /usr/local/lib/python3.7/dist-packages (from folium>=0.11.0->geemap) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found