Search code examples
pythonpygamepyinstallerexeassets

Pyisntaller No Such File Or Directory


I have created a script with pygame and it requires one file which is a font named "blocky.ttf" inside the "assets" folder. I have given a relative path inside my python script. The problem occurs when I use pyinstaller to convert to it to exe. When I open the exe file it shows an error that this font file doesn't exist in the temp folder something like "MEI" and then some numbers.

I am using this to get the path of the font:

try:
    base_path = sys._MEIPASS
except Exception:
    base_path = os.path.abspath(".")

font_path = os.path.join(base_path, 'assets\\blocky.ttf')

I tried to copy my assets folder to the "dist" folder. No good news. I have also tried different solutions from StackOverflow but nothing worked.

This is the command I am using to convert to exe:

pyinstaller --onefile -w 'main.py'

Python: 3.9.6

Pyinstaller: 4.4

OS: Windows 10


Solution

  • Auto-py-to-exe solved my problem. It is a GUI which generates pyinstaller command based on the options you select and run it. No headache of CLI. Selecting the required files and folder is really easy. Just browse and select.

    Here is the link: https://pypi.org/project/auto-py-to-exe/