3

I'm attempting to use PyInstaller to compile one of the demo scripts for Asciimatics, in hopes to eventually be able to create a simple GUI for a text-based game I'm developing, and it returns the following error:

C:\Users\X\Documents\Python Scripts\asciimatics samples\dist\test>test.exe

Traceback (most recent call last):
  File "site-packages\setuptools-19.2-py3.4.egg\pkg_resources\__init__.py", line 443, in get_provider
KeyError: 'pyfiglet.fonts'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 22, in <module>
  File "site-packages\asciimatics\screen.py", line 859, in wrapper
  File "<string>", line 12, in demo
  File "site-packages\asciimatics\renderers.py", line 276, in __init__
  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\setuptools-19.2-py3.4.egg\pkg_resources\__init__.py", line 1160, in resource_exists
  File "site-packages\setuptools-19.2-py3.4.egg\pkg_resources\__init__.py", line 445, in get_provider
ImportError: No module named 'pyfiglet.fonts'
test returned -1

Googling this error returned this thread, but it seems to me that the error is caused by a fault within SublimeFiglet itself, and was fixed two years ago.

I'm using Python 3.4 on Windows 10. I had to downgrade setuptools to 19.2 (I believe is the version I had to downgrade to) because I was getting an error stating that the packaging package was missing when attempting to run the compiled .exe file.

I've imported both the six (due to it being a hidden import) and pyfiglet modules in test.py, in addition to the other imports necessary to run the script. Importing pyfiglet and any variations I can think of changes nothing. I could change the spec file to add a hidden import for six, though I don't see how that would change anything.

Here is the spec file Pyinstaller uses:

block_cipher = None


a = Analysis(['test.py'],
             pathex=['C:\\Users\\Sirindil\\Documents\\Python Scripts\\asciimatics samples'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='test',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='test')

Every sample script included with Asciimatics returns this same error for me. I've tried using different options when running pyinstaller on the script, with no success. Am I missing something? I have no idea how to fix this.

James Burns
  • 31
  • 1
  • 1
  • 5

8 Answers8

6

I was also facing the same issue and i have imported the pyfiglet folder inside in exe and it works for me. I'm having venv folder as a virtual environment but in case you are having different virtual environment folder name then change the folder name as well, otherwise only change the AppName.py.

pyinstaller --add-data "venv\Lib\site-packages\pyfiglet;./pyfiglet" AppName.py
Ritesh Singh
  • 121
  • 2
  • 4
3

For me the simplest way to solve this was to pass --collect-all pyfiglet when running pyinstaller. This seems to just include the entire library quite easily.

0

It looks like you're building your EXE without including the font files from pyfiglet. This is because PyInstaller cannot interpret the pkg_resources call from inside pyfiglet when building the set of files to package up.

I've not used it myself, but it looks like you might be able to add the font files to your package by updating your spec file to include all the missing files. However, you should pay attention to the FAQ, which says that there is only limited support for pkg_resources (and so it may be that you simply cannot package pyfiglet).

Peter Brittain
  • 13,489
  • 3
  • 41
  • 57
0

The question is quite old but I had the same issue and solved it by simply copy/pasting the pyfiglet folder from PYTHONPATH\Lib\site-packages to the pyinstaller dist folder.

Darth Vagrant
  • 139
  • 3
  • 13
0

Provide the path of the Pyfiglet folder on the system in the PyInstaller command options, which will copy the files into the generated dist.

Eg .:

pyinstaller --add-data "C:/Program Files/Python35/Lib/site-packages/pyfiglet";./pyfiglet MyApp.py

Or for a single EXE file:

pyinstaller --onefile --add-data "C:/Program Files/Python35/Lib/site-packages/pyfiglet";./pyfiglet MyApp.py

Assuming your App name is "MyApp.py", your system is Windows and the Pyfiglet lib is installed at the following path: C:/Program Files/Python35/Lib/site-packages/pyfiglet

Otherwise, change to the correct values.

  • This syntax is not correct. The quote in the argument for --add-data terminates too early. It should be: `pyinstaller --add-data "C:/Program Files/Python35/Lib/site-packages/pyfiglet;./pyfiglet" MyApp.py` – Omar Shehata Jun 11 '19 at 23:29
0

Try the below code before you start your work...!

!pip install pyfiglet

Hope it should work..!

GOPI A.R
  • 61
  • 2
  • Please provide more details in which circumstance the dependency installation worked, for example the dependency version, python version and OS (the question relies on Python 3.4 on Windows 10). – manasouza Aug 25 '20 at 12:16
0

Hello there I have experienced this issue but the problem is python 3.9 update you have to chose python 3.8 as interpreter ..

0

Install Specific Version:

pip install pyfiglet

Upgrade pyfiglet

sudo pip3 install --upgrade pyfiglet

Getting Dependency Error in Window 10 Use code: easy_install instead of pip install

easy_install pyfiglet

Upgrade using easy install

sudo easy_install --upgrade  pyfiglet

On OSX System to install Module: Use code: brew install instead of pip install

brew install pyfiglet 

Without Using Pip :

sudo apt-get install -y pyfiglet 

On CentOS7 or Linux Fedora:

yum -y install pyfiglet 

Or on Fedora try

sudo dnf install pyfiglet 

Command if Homebrew screws up your path on macOS:

python -m pip install pyfiglet 

For Python3 MacOs Homebrew screws

python3 -m pip install pyfiglet 

Verify module from list MacOs

 pip freeze | grep  pyfiglet

For Execute on Anaconda as your python package manager

conda install -c anaconda pyfiglet