Repository navigation
Cannot use python esc/pos library #8659
Description
Activity
- addedtriagePlease triage and relabel this issuePlease triage and relabel this issue
on Jul 16, 2024 Have you tried adding
--collect-data=escposto your pyinstaller command?Have you tried adding
--collect-data=escposto your pyinstaller command?Thank you for the prompt response.
I was using:
--add-data "venv/Lib/site-packages/escpos/capabilities.json;escpos"without luck now I tried what you suggested but it's still not finding that file.What version of
PyInstallerand what version ofescposare you using?What version of
PyInstallerand what version ofescposare you using?
Thanks for your reply. Here are the versions.
Pyinstaller 6.4.0
python-escpos Version: 3.1Version: 3.1
Ah yes, this is
python-escpos, notescpos.Version: 3.1
Ah yes, this is
python-escpos, notescpos.
It's actually the same library https://pypi.org/project/escpos/ github page is https://github.com/python-escpos/python-escpos
Inside my virtual environment it's in a folder called escpos, so--collect-data=escposis correct isn't it?Inside my virtual environment it's in a folder called escpos, so --collect-data=escpos is correct isn't it?
It is, but it seems there's a problem with path that we return for
importlib_resources.files(__name__)in frozen application.Until I figure out what it is and fix it, you can use this as a work around:
import sys if getattr(sys, 'frozen', False): import os os.environ['ESCPOS_CAPABILITIES_FILE'] = os.path.join(sys._MEIPASS, 'escpos', "capabilities.json") import escpos.printer
Looks like we return submodule path as if it were a package, rather than returning its package path.
I.e., in unfrozen python, printing
importlib_resources.files(__name__)from package / submodule / subpackage / submodule-in-subpackage gives:IN PACKAGE: [...]\mypkg IN SUBMODULE: [...]\mypkg IN SUBPACKAGE: [...]\mypkg\mysubpkg IN SUBPACKAGE SUBMODULE: [...]\mypkg\mysubpkgand in frozen application, it is:
IN PACKAGE: [...]\program\_internal\mypkg IN SUBMODULE: [...]\program\_internal\mypkg\mymod IN SUBPACKAGE: [...]\program\_internal\mypkg\mysubpkg IN SUBPACKAGE SUBMODULE: [...]\program\_internal\mypkg\mysubpkg\mysubmod- added and removedtriagePlease triage and relabel this issuePlease triage and relabel this issue
on Jul 16, 2024 Until I figure out what it is and fix it, you can use this as a work around:
import sys if getattr(sys, 'frozen', False): import os os.environ['ESCPOS_CAPABILITIES_FILE'] = os.path.join(sys._MEIPASS, 'escpos', "capabilities.json") import escpos.printer
Thank you!
I take it build using--add-data "venv/Lib/site-packages/escpos/capabilities.json;escpos"and--collect-data escposit worked btw. I'll keep an eye out for future releases.
Thanks again!- added 2 commits that reference this issue
on Jul 17, 2024 - added a commit that references this issue
on Jul 18, 2024 Thanks again for this. Can we expect this in the next release?
- locked as resolved and limited conversation to collaborators
on Sep 21, 2024
I am trying to build using the python escpos library, my build is fine without it https://github.com/python-escpos/python-escpos
However any reference to escpos library crashes the program, here's the errors:
I am not sure why it's looking in a folder called capabilities when the capabilities.json is in escpos folder. There is no such folder.
In capabilities.py line 24
there is a ref to the file,
ref = importlib_resources.files(__name__) / "capabilities.json"which I thought could be the issue but I am not sure. Any help is appreciated.Thank you!