Skip to content
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

Files not found after packaging #5256

Closed
Phoenix009 opened this issue Oct 15, 2020 · 2 comments · Fixed by pyinstaller/pyinstaller-hooks-contrib#62
Closed

Files not found after packaging #5256

Phoenix009 opened this issue Oct 15, 2020 · 2 comments · Fixed by pyinstaller/pyinstaller-hooks-contrib#62

Comments

@Phoenix009
Copy link

I am making a python application that uses the folium python package. The application is getting built successfully however, when I run the application I get the following error
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/Desktop/application/src/dist/main/branca/_cnames.json'

As mentioned in the official document that pysinstaller by default skips the data files I tried the solution mentioned there but did not solved the issue. I tried solving the issue using #4809, this and by using custom hooks as mentioned in #5247 but even that did not work.
I am using Python version 3.8.5 on a Ubuntu system and folium version 0.11.0

Following is a minimal example of my application

import folium
print("Hello World")
@rokm
Copy link
Member

rokm commented Oct 15, 2020

The missing data file issue can be fixed using

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('branca')

either in your spec file (with passing the resulting datas to Analysis) or in a custom hook-branca.py hook.

But once that is sorted out, you will hit the problem with the lack of support for pkg_resources (#4881) similar to #5247. I guess in this case, you could try working around that by patching site-packages/branca/element.py to use jinja2.FileSystemLoader instead of jinja.PackageLoader when dealing with a frozen application. I.e., expand the line:

ENV = Environment(loader=PackageLoader('branca', 'templates'))

into

import sys
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
    import os
    from jinja2 import FileSystemLoader
    bundle_dir = getattr(sys, '_MEIPASS')
    data_dir = os.path.abspath(os.path.join(bundle_dir, 'branca', 'templates'))
    ENV = Environment(loader=FileSystemLoader(data_dir))
else:
    ENV = Environment(loader=PackageLoader('branca', 'templates'))

@Phoenix009
Copy link
Author

Thanks a lot! that did it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants