New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Folium doesn't package as expected when compiling to an executable #1081
Comments
I don't know any of those tools and I'm not familiar with the process of creating an With that said, if you can provide any details of those tools and its limitations/expectations of a package it would help us debug this. I Google about some of them and it seems that there are a number of limitations! Closing this b/c |
@ocefpaf Ok let's forget the exe issue for now. Is it problematic that |
OK.
Problematic? Yes. I could not reproduce that with
You probably just need an update. |
Upgraded fine and It seems that one of the dependencies of folium is branca, is that correct or am I mistaken? The error that I see when I run my exe refers to a file called _cnames.json which is in the site-packages/branca folder. Could this potentially be a branca issue or is there something about how folium 'talks' to branca that could be an issue? Pardon my understanding of this, I'm still very new to Python and coding and just trying to learn how to properly track down problems that I encounter. I appreciate your help. |
🎉
That is correct.
It is probably a
No problem. I do recommend you to move this discussion to branca though. |
Gotcha, I'll head over to branca. Thanks! |
Hi @nathan3leaf, |
@FabeG
|
@nathan3leaf could you try to add in the list of packages
|
@FabeG This is actually the same error I've been receiving when using cx_freeze, so it's getting tripped up in the same spot. |
@nathan3leaf |
@FabeG |
|
@FabeG |
I see now that my setuptools may be out of date |
I updated setuptools and no longer see the traceback related to pkg_resources or asyncio. However, in my script I have these lines:
which apparently it doesn't like because now I get an error that |
Seems you are about to solve your problem: for a frozen exe, you have to use
|
@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! |
Could you please tell me the file name to add the code is it console.py or startup.py |
The last few code samples above were all added to my main project file, which of course would be different for you. However, the setup.py file which needs to be created in order to use cx_freeze, is also referenced above, which I've pasted below.
|
Can you guide me step by step i am new to python |
I had to be guided through the process myself, so I'm not sure I'm the one to provide the guidance. However, if you read this thread, you'll see that I had to essentially make three adjustment: 1. updated various packages that I was using - Tkinter, folium, setuptools, branca and some others. 2. I had to create and customize the setup.py file which tells cx_freeze where some things are and what should be included in the exe. 3. I had to update my file that contained the heart of my program's code, telling it what to do in the event it's 'frozen' as an exe. |
i have done step 1 and 2 , the only problem i am trying to understand is to add this code - i mean to the main program or any specific file
plus i am trying to understand where to add the following code part too
|
In my program, I had several references to paths that I need to access. For example, if the user wants to view some details related to a building at a specific street address, a database would be referenced and the data would be retrieved from there. So, my old syntax may have been: homeDir = "C://source//data.db" Once an exe is made, this file path could have posed a problem if the user saved their exe in a different folder than what I did. So instead, at the start of my program, just after all of my imports, I have this:
The resource_path method helps to properly align where the program is looking for a file, relative to the location where the exe is saved. So, unless you have references in your program that are you file and folder locations. you don't need that module. As for the second part:
Add this at the beginning of your script, just after your imports and before the primary code of your program. |
The formatting of the code is throwing me off a little but I'll do my best to offer some ideas as to what would need to be changed. It looks like you have two instances of the
So the variable homeDir uses |
Hi @Uzair919, |
@FabeG i am using windows 10 64 and python 3.7 |
It seems that your |
@FabeG Hi again, so my EXE started working , but i couldnt understand why my plots are not being saved in the desired directory ? any help in this regard , |
Hello, after having a play with it, I managed to compile it with PyInstaller. The problem has to do with relative paths, so changing the working directory within runtime and a few changes in the code does the trick. I stored some of the jsons in a python script as a quick fix, please check. (branca)
Create a script (jsons.py) with this:
(folium) raster_layers.py
Lastly, when you compile, attach "folium\templates" to the location of your executable. Please, bear in mind this is just a quick fix, probably you will need a better code to account for other OS. |
Please add a code sample or a nbviewer link, copy-pastable if possible
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 errorAttributeError: 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 ifGeoJsonStyle
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
The text was updated successfully, but these errors were encountered: