dahlia / iterfzf

Pythonic interface to fzf, a CLI fuzzy finder
https://pypi.python.org/pypi/iterfzf
GNU General Public License v3.0
164 stars 19 forks source link

Incompatibility with PyInstaller on Windows #5

Open oerpli opened 4 years ago

oerpli commented 4 years ago

I tried to create an executable with PyInstaller from my script (pyinstaller --onefile script.py). This results in the following error:

Traceback (most recent call last):
  File "script.py", line 10, in <module>
    import iterfzf as fzf
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "C:\miniconda3\current\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\iterfzf\__init__.py", line 15, in <module>
  File "site-packages\pkg_resources\__init__.py", line 1134, in resource_exists
  File "site-packages\pkg_resources\__init__.py", line 1404, in has_resource
  File "site-packages\pkg_resources\__init__.py", line 1473, in _has
NotImplementedError: Can't perform this operation for unregistered loader type
[26980] Failed to execute script script

I am not sure if this problem is from PyInstaller or from iterfzf - I found a maybe related issue in their repo, with various other packages that are affected: https://github.com/pyinstaller/pyinstaller/issues/2752

OS: Windows 10 Python: 3.7.3 PyInstaller: 3.5 iterfzf: 0.5.0.17.5 (installed from github; had the same issue with latest version from pip)

dahlia commented 4 years ago

This projects depends on some hackish way to bundle fzf binaries for multiple platforms into wheels by extending internal features of setuptools, Python's packaging framework. So it's indeed likely to break PyInstaller in any way. Frankly, I don't have any experience on PyInstaller, and have no spare time to deeply look into that. If someone sends a patch to fix this problem I'm going to review as soon as possible. Thanks!

danihodovic commented 2 years ago

The same problem applies to Linux too.

https://github.com/nk412/pyfzf doesn't have this problem, but you have to bundle fzf yourself.

dahlia commented 1 year ago

We've recently revamped the way it packages and vendors fzf. Could you try again with the latest release?

Gregory-K commented 5 months ago

It works, but not as simple as pyinstaller script.py

One has to edit their script.spec file
(more info on the pyinstaller docs)
OR use the --add-binary argument.

Better to just create the .spec without using the cli arguments. A plain text .spec is easier to edit/tinker-with, and certainly easier to re-use (pyinstaller --noconfirm /path/to/script.spec).

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

a = Analysis(['script.py'],
             pathex=['path/to/script'],  # Edit
             binaries=[('path/to/iterfzf/fzf_binary', 'iterfzf')],  # Edit path/to
             datas=[],  # can work here too, it seems the distinction is more about semantics (?)
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

# ...
# rest of configuration

then pyinstaller /path/to/script.spec