使用pyinstaller将pygame应用程序转换为可执行文件时出现字体错误 [英] Error with fonts when using pyinstaller to convert a pygame app to executable

查看:117
本文介绍了使用pyinstaller将pygame应用程序转换为可执行文件时出现字体错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个pygame应用,该应用具有一个主python文件和一个资产文件夹.我已经使用pyinstaller将应用程序转换为可执行文件,但是每次收到错误-解决它们时,都会出现不同的错误.我怀疑我最近遇到的错误与pygame文件中的文本有关.

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.

这是我使用的pygame字体行:

This is the pygame font line I used:

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

我尝试使用.ttf文件并将其复制到与main.py文件相同的文件夹中,但是那也不起作用.我还要确保将资产文件夹复制到与main.app文件相同的文件夹中,但这也没有帮助.

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!

推荐答案

如果使用ttf文件,则需要直接导入它们而不是使用 SysFont .例如:

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还需要放置在可执行文件所在的文件夹中,或者,如果您的文件夹结构更深,请使用相对路径(并且文件夹也必须位于可执行文件旁边):

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)

出于测试目的,使用以下命令来查看您从哪个文件夹开始,设置相对路径以及知道要在哪里查找ttf文件也可能会有所帮助:

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() 

这篇关于使用pyinstaller将pygame应用程序转换为可执行文件时出现字体错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆