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

pkg_resources.DistributionNotFound: The 'PyInstaller'... #5275

Closed
Salim9304 opened this issue Oct 22, 2020 · 4 comments
Closed

pkg_resources.DistributionNotFound: The 'PyInstaller'... #5275

Salim9304 opened this issue Oct 22, 2020 · 4 comments

Comments

@Salim9304
Copy link

OS: Linux
pyinstaller: v4.0
environment: pipenv
python: v3.7

I would like to put together a simple code using the 'Folium' library
simple code

program.py

from PyInstaller.utils.hooks import collect_data_files
datas += collect_data_files('branca', subdir='templates')
datas += collect_data_files('folium', subdir='templates')
    
import folium
print("Hello!")

pyinstaller -F --clean program.py
OK

when I try to run the executable I get the error:
_Traceback (most recent call last):
File "program.py", line 1, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in load_unlocked
File "/home/salim/.local/share/virtualenvs/folium-7tyjei-/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.dict)
File "PyInstaller/init.py", line 55, in
File "pkg_resources/init.py", line 465, in get_distribution
File "pkg_resources/init.py", line 341, in get_provider
File "pkg_resources/init.py", line 884, in require
File "pkg_resources/init.py", line 770, in resolve
pkg_resources.DistributionNotFound: The 'PyInstaller' distribution was not found and is required by the application
[15296] Failed to execute script 1

I tried to solve the problem as stated here:
#5256
#5262

I opened the file:
site-packages/branca/element.py
Replaced the line:
ENV = Environment(loader=PackageLoader('branca', 'templates'))
to

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'))

and
site-packages/folium/raster_layers.py
ENV = Environment(loader=PackageLoader('folium', 'templates'))
to

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, 'folium', 'templates'))
    ENV = Environment(loader=FileSystemLoader(data_dir))
else:
    ENV = Environment(loader=PackageLoader('folium', 'templates'))

No effect the same error. Is there any way to solve the problem?

@rokm
Copy link
Member

rokm commented Oct 22, 2020

You're getting the error because you are trying to import PyInstaller in your program.

This block

from PyInstaller.utils.hooks import collect_data_files
datas += collect_data_files('branca', subdir='templates')
datas += collect_data_files('folium', subdir='templates')

should be placed into your .spec file, not the program (.py) file.

@Salim9304
Copy link
Author

Salim9304 commented Oct 22, 2020

You're getting the error because you are trying to import PyInstaller in your program.

This block

from PyInstaller.utils.hooks import collect_data_files
datas += collect_data_files('branca', subdir='templates')
datas += collect_data_files('folium', subdir='templates')

should be placed into your .spec file, not the program (.py) file.

Are you sure this Linux solution works?

my code
program.py

import folium
print("Hello!")

my spec

mode: python ; coding: utf-8

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('branca', subdir='templates')
datas += collect_data_files('folium', subdir='templates')

block_cipher = None


a = Analysis(['program.py'],
             pathex=['/home/salim/test/folium'],
             binaries=[],
             datas=datas,
             hiddenimports=['geopandas.datasets','branca','folium'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='program',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )

pyinstaller -F --clean program.spec
OK

after running the executable:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/_MEIFug4aJ/branca/_cnames.json'

@Phoenix009
Can you share your solution?

@rokm
Copy link
Member

rokm commented Oct 22, 2020

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/_MEIFug4aJ/branca/_cnames.json'

You need to collect all branca data files, not just its template subfolder:

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('branca')
datas += collect_data_files('folium', subdir='templates')

@Salim9304
Copy link
Author

Good.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants