简体   繁体   中英

Error with fonts when using pyinstaller to convert a pygame app to executable

I created a pygame app that has one main python file and an assets folder. I have used pyinstaller to convert the app to an executable file, but every time I receive errors - when I resolve them, different errors come up. I suspect the errors I have been getting recently have to do with the text in my pygame file.

This is the pygame font line I used:

font = pygame.font.SysFont("Arial", 32)

I have tried using.ttf files and copying them into the same folder as my main.py file, but that didn't work either. I also make sure to copy my assets folder into the same folder as the main.app file, but that has not helped either.

I am not sure what this error message is telling me, and there seems to be no other question with this same message (there is no line in my code that is referenced in this error message for me to check).

Fatal Python error: (pygame parachute) Segmentation Fault
Traceback (most recent call last):
  File "pygame/pkgdata.py", line 50, in getResource
  File "site-packages/pkg_resources/__init__.py", line 1134, in resource_exists
  File "site-packages/pkg_resources/__init__.py", line 1404, in has_resource
  File "site-packages/pkg_resources/__init__.py", line 1473, in _has
NotImplementedError: Can't perform this operation for unregistered loader type

Any help would be amazing, thank you!

If you use ttf-files, then you need to import them directly instead of using SysFont . So as an example:

size = 12
myfont = pygame.font.Font("Arial.ttf",size)

Arial.ttf also needs to be placed in the same folder where your executable is, or if you have a deeper folder structure, use relative paths (and the folders need to be next to your executable as well):

size = 12
myfont = pygame.font.Font("./myfolder/Arial.ttf",size)

For testing purposes it might also help to use the following command to see from which folder you start, to set your relative path and to know where you are looking for the ttf file:

import os    
os.getcwd() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM