Comments (11)
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.
Does this work?
from PyInstaller.utils.hooks import collect_all
datas, binaries, hiddenimports = collect_all("pyfiglet")
from pyinstaller-hooks-contrib.
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.
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.
@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.
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.
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.
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.
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.
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.
@benduckwdesign , great suggestion... My issue was resolved by this!
from pyinstaller-hooks-contrib.
Related Issues (20)
- hook-rtree.py: libspatialindex is either not installed ... HOT 2
- ModuleNotFoundError: No module named 'dbus_fast._private.marshaller' HOT 1
- for python3 it is no need `prettytable` hooks HOT 2
- Missing imports during packaging with PyInstaller 5.13 and pyinstaller-hooks-contrib 2023.12 HOT 2
- ImportError: cannot import name '_pylon' from 'pypylon' after pyinstaller 6.3.0 HOT 2
- OpenCV missing data files in /cv2/data directory HOT 1
- sklearn dropped neighbors._typedef in version 1.0.2 HOT 1
- Add PyInstaller in 'I want to help' section HOT 2
- Falcon hook
- PyInstaller: Unable to find '/usr/sbin/neato' when adding binary and data files HOT 8
- hook-transformers fails to run due to partially initialized huggingface_hub HOT 4
- cryptography with OpenSSL 3.x HOT 18
- `gcloud-aio-*` (and probably also `gcloud-rest-*`) trigger `gcloud` hook, which fails because `gcloud` is not installed. HOT 1
- 2024.5 issue importing cryptography hook during build HOT 15
- pyarrow HOT 8
- Trying to import "isolated" from "PyInstaller" when pyinstaller version is lower than 5 HOT 1
- A problem converting a grib2 file to a netCDF file using cfgrib and xarray HOT 4
- pysintaller with scipy HOT 9
- hook-cryptography 2024.7 is incompatible with pyinstaller 4.5.1 HOT 1
- Create version tag after commiting to changelog HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyinstaller-hooks-contrib.