Coder Social home page Coder Social logo

Comments (11)

benduckwdesign avatar benduckwdesign commented on August 18, 2024 3

I understand there is a different issue at hand here, but for anyone looking to quickly use pyfiglet with pyinstaller, doesn't this "just work" by adding a few things to the app.spec? (It seems to work for me.)

hiddenimports=['pyfiglet.fonts'],
datas=[('[insert full path to site packages]/pyfiglet/fonts/standard.flf','pyfiglet/fonts')],

Good luck on the issue everyone.
EDIT: You'll also need @caramelomartins snippet.

from pyinstaller-hooks-contrib.

bjones1 avatar bjones1 commented on August 18, 2024 1

Does this work?

from PyInstaller.utils.hooks import collect_all

datas, binaries, hiddenimports = collect_all("pyfiglet")

from pyinstaller-hooks-contrib.

caramelomartins avatar caramelomartins commented on August 18, 2024 1

I've found a workround that has worked for me and might work for other people too, so I'd like to share it. I've added the following as a PyInstaller hook (hook-pyfiglet.py):

Does this work?

from PyInstaller.utils.hooks import collect_all

datas, binaries, hiddenimports = collect_all("pyfiglet")

This seems to have resolved the import issues, as expected, but raised the error NotImplementedError: Can't perform this operation for unregistered loader type, as said in https://github.com/pyinstaller/pyinstaller/issues/2389#issuecomment-420941860.

I've followed what has been discussed in pyinstaller/pyinstaller#2748 and understood that the issue was now related to the fact that a runtime hook was registering the pkg_resources.NullProvider. Since adding another runtime hook wouldn't resolve the problem, as the installed ones would have processed afterwards, I ended up adding the following snippet to my script:

import pkg_resources
import sys

from pyimod03_importers import FrozenImporter

if getattr(sys, 'frozen', False):
   pkg_resources.register_loader_type(FrozenImporter, pkg_resources.DefaultProvider)

In essence, instead of registering NullProvider, we now register FrozenImporter with DefaultProvider, which inherits from NullProvider anyway.

Now, this works for me but I cannot guarantee this doesn't have side effects, use with caution please. Nonetheless, since it has worked for me and the issues haven't been fixed yet, I thought someone might have been interested in a workaround.

I have noticed this issue is dependent on pyinstaller/pyinstaller#2748 , which is itself dependent on another issue. I'm not sure if this workaround helps in figuring out a way of solving any of those issues but if there's any approach you think could be taken, I don't mind trying to help.

from pyinstaller-hooks-contrib.

htgoebel avatar htgoebel commented on August 18, 2024

Thanks for this hook. Would you please send a pull-request? And please mind adding

  • the copyright header you can see in the other hooks (mind that we have 2017 now :-)
  • a comment with the url to pyfiglet and
  • which version you have tested it with.

Thanks.

from pyinstaller-hooks-contrib.

nejch avatar nejch commented on August 18, 2024

@DeflatedPickle did you actually get this hook to work? I don't think it does with current versions of pyinstaller and pyfiglet. The package uses pkg_resources to load fonts, resulting in errors similar to pyinstaller/pyinstaller#1898:

    f = Figlet(font='slant')
  File "lib\site-packages\pyfiglet\__init__.py", line 710, in __init__
  File "lib\site-packages\pyfiglet\__init__.py", line 717, in setFont
  File "lib\site-packages\pyfiglet\__init__.py", line 90, in __init__
  File "lib\site-packages\pyfiglet\__init__.py", line 100, in preloadFont
  File "lib\site-packages\pkg_resources\__init__.py", line 1191, in resource_exists
  File "lib\site-packages\pkg_resources\__init__.py", line 1459, in has_resource
  File "lib\site-packages\pkg_resources\__init__.py", line 1509, in _has
NotImplementedError: Can't perform this operation for unregistered loader type

So I think this depends on pyinstaller/pyinstaller#2748 unless you provide the font parameter as a filename to avoid using pkg_resources - see below the relevant code for reference:

def preloadFont(cls, font):
        """
        Load font data if exist
        """
        for extension in ('tlf', 'flf'):
            fn = '%s.%s' % (font, extension)
            if pkg_resources.resource_exists('pyfiglet.fonts', fn):
                data = pkg_resources.resource_string('pyfiglet.fonts', fn)
                data = data.decode('UTF-8', 'replace')
                return data
            elif os.path.isfile(font):
                with open(font, 'rb') as f:
                    return f.read().decode('UTF-8', 'replace')
        else:
            raise FontNotFound(font)

from pyinstaller-hooks-contrib.

ossie-git avatar ossie-git commented on August 18, 2024

Was anyone able to get scripts using pyfiglet to work? I tried the above hook which didn't work and then tried updating my spec to include the font files as shown below:

 datas=[('/usr/local/lib/python2.7/site-packages/pyfiglet/fonts','.')],

It creates the executable but when I run it, I get the following:

Traceback (most recent call last):
  File "app.py", line 242, in <module>
    cprint(figlet_format(banner, font="standard"),"blue")
  File "site-packages/pyfiglet/__init__.py", line 43, in figlet_format
  File "site-packages/pyfiglet/__init__.py", line 710, in __init__
  File "site-packages/pyfiglet/__init__.py", line 717, in setFont
  File "site-packages/pyfiglet/__init__.py", line 90, in __init__
  File "site-packages/pyfiglet/__init__.py", line 100, in preloadFont
  File "site-packages/pkg_resources/__init__.py", line 1161, in resource_exists
  File "site-packages/pkg_resources/__init__.py", line 419, in get_provider
ImportError: No module named fonts
Failed to execute script app

I'm kind of surprised that this isn't working considering that a lot of scripts make use of pyfiglet. Thanks.

from pyinstaller-hooks-contrib.

Overdrivr avatar Overdrivr commented on August 18, 2024

I'm having the same issue with pyfiglet, even with collect_data_files('pyfiglet'), I get NotImplementedError: Can't perform this operation for unregistered loader type.

@htgoebel Can you confirm that for this ticket to be solved it would take either:

  • pyinstaller/pyinstaller#2748 being implemented
  • pyfiglet stops using pkg_resources
  • use the font name directly so that pyfiglet does not call pkg_resources

from pyinstaller-hooks-contrib.

SeeDoubleYou avatar SeeDoubleYou commented on August 18, 2024

Does this work?

from PyInstaller.utils.hooks import collect_all

datas, binaries, hiddenimports = collect_all("pyfiglet")

No, unfortunately it doesn't. This still results in a ModuleNotFoundError on pyfiglet.fonts

from pyinstaller-hooks-contrib.

bjones1 avatar bjones1 commented on August 18, 2024

Hmm. Try running PyInstaller with --log-level=DEBUG and --debug=all. Look at the output of the build to see if pyfiglet files are picked up. Look at the files in dist/ to see what's missing.

from pyinstaller-hooks-contrib.

caramelomartins avatar caramelomartins commented on August 18, 2024

Sorry @Thonleb, I don't have a solution for you. Since this is dependent on a few outstanding issues to be properly solved, I guess you can only get something working (hacked) by trial and error. Do you have more details about what "it totally bugs my code" means?

from pyinstaller-hooks-contrib.

vaibhavard avatar vaibhavard commented on August 18, 2024

@benduckwdesign , great suggestion... My issue was resolved by this!

from pyinstaller-hooks-contrib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.