Hey all. Relatively new to writing code, but here it goes:
I am writing a small, simple game to be played in the terminal window. Part of the game involves using pyfiglet’s fonts.
I’ve tried for many hours to get pyinstaller to compile it, however I’m always met with various errors. Namely, I believe the issue is pyinstaller not pulling the necessary information into the .exe and I get errors with all of the methods I’ve researched to date. I’m currently trying to compile with pyinstaller, using pycharm on a windows 10 laptop.
If I simply compile within pycharm using pyinstaller and then try to open the .exe by double clicking on it, a cmd window appears for a brief moment then disappears. When I go into a command terminal window and execute the program that way, I get the following:
Traceback (most recent call last):
File "pyfiglet_compile.py", line 50, in <module>
File "pyfiglet_compile.py", line 8, in intro
File "pyfiglet\__init__.py", line 65, in figlet_format
File "pyfiglet\__init__.py", line 794, in __init__
File "pyfiglet\__init__.py", line 801, in setFont
File "pyfiglet\__init__.py", line 126, in __init__
File "pyfiglet\__init__.py", line 147, in preloadFont
pyfiglet.FontNotFound: banner3-d
[988] Failed to execute script 'pyfiglet_compile' due to unhandled exception!
Python 3.11.1 is the version I have on this machine.
Any idea how I can successfully tell pyinstaller to include the needed fonts ?
At any rate, here’s some code I took off a youtube video that produces the same result - runs fine for me in pycharm, but when packaged with pyinstaller and double clicked, a black window appears briefly and disappears. The same errors above appear when running the .exe in a cmd window.
Below is code taken from a youtube video.
import sys
from pyfiglet import Figlet
import random
figlet = Figlet()
if len(sys.argv) == 1:
isRandomFont = True
elif len(sys.argv[1] == "-f" or sys.argv[1] == "--font"):
isRandomFont = False
else:
sys.exit(1)
msg = input("Input: ")
figlet.getFonts()
if isRandomFont == False:
try:
figlet.setFont(font=sys.argv[2])
print(figlet.renderText(msg))
except:
print("Invalid usage")
sys.exit(1)
else:
font = random.choice(figlet.getFonts())
print(figlet.renderText(msg))
Below is the output when ran in a cmd window:
C:\Users\...\Python_Projects\dist>test.exe
Traceback (most recent call last):
File "pkg_resources\__init__.py", line 356, in get_provider
KeyError: 'pyfiglet.fonts'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 5, in <module>
File "pyfiglet\__init__.py", line 794, in __init__
File "pyfiglet\__init__.py", line 801, in setFont
File "pyfiglet\__init__.py", line 126, in __init__
File "pyfiglet\__init__.py", line 136, in preloadFont
File "pkg_resources\__init__.py", line 1144, in resource_exists
File "pkg_resources\__init__.py", line 358, in get_provider
ModuleNotFoundError: No module named 'pyfiglet.fonts'
[27176] Failed to execute script 'test.py' due to unhandled
exception!