В последнее время я перешел к Pygame, и я начал следить за учебниками. Всё побежал нормально, пока я не достиг программу, которая выглядит так:Как преодолеть шрифты Python (Pygame), которые не загружаются
"""
A python graphics introduction.
This simple program draws lines at a 45 degree angle from one side
of the screen to the other.
"""
# Import a library of functions called 'pygame'
import pygame
from pygame import font
# Initialize the game engine
pygame.init()
# Set the height and width of the screen
size = (400, 500)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Intro to Graphics")
#Loop until the user clicks the close button.
done = False
clock = pygame.time.Clock()
# Loop as long as done == False
while not done:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
# All drawing code happens after the for loop and but
# inside the main while not done loop.
# Clear the screen and set the screen background
screen.fill(WHITE)
# Select the font to use, size, bold, italics
font = pygame.font.SysFont('Calibri', 25, True, False)
# Render the text. "True" means anti-aliased text.
# Black is the color. This creates an image of the
# letters, but does not put it on the screen
text = font.render("My text", True, BLACK)
# Put the image of the text on the screen at 250x250
screen.blit(text, [250, 250])
# Go ahead and update the screen with what we've drawn.
# This MUST happen after all the other drawing commands.
pygame.display.flip()
# This limits the while loop to a max of 60 times per second.
# Leave this out and we will use all CPU we can.
clock.tick(60)
# Be IDLE friendly
pygame.quit()
Когда бегала я получаю сообщение об ошибке при шрифта = pygame.font.SysFont («Calibri», 25, True, False) что выглядит следующим образом:
RuntimeWarning: use font: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/font.so, 2): Library not loaded: /usr/X11/lib/libfreetype.6.dylib
Referenced from: /Library/Frameworks/SDL_ttf.framework/Versions/A/SDL_ttf
Reason: image not found
(ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/font.so, 2): Library not loaded: /usr/X11/lib/libfreetype.6.dylib
Referenced from: /Library/Frameworks/SDL_ttf.framework/Versions/A/SDL_ttf
Reason: image not found)
pygame.font.init()
Traceback (most recent call last):
File "IntroGraphics.py", line 15, in <module>
pygame.font.init()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 70, in __getattr__
raise NotImplementedError(MissingPygameModule)
NotImplementedError: font module not available
(ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/font.so, 2): Library not loaded: /usr/X11/lib/libfreetype.6.dylib
Referenced from: /Library/Frameworks/SDL_ttf.framework/Versions/A/SDL_ttf
Reason: image not found)
Я посмотрел здесь для ответа, и только другой пост об этом включает в себя 32-битный Pygame с 64-битным Python. Я убедился, что обе они работают на 32-битных (несмотря на то, что это 64-разрядная машина, Pygame - только 32-разрядная версия). Я запускаю Python 2.7.9 Fresh Install
Другие места говорят, что это проблема с SDL, но я неопытный с SDL, и я не знаю, что делать.
У кого-нибудь еще была эта проблема?
Вы установили sdl_ttf? http://www.libsdl.org/projects/SDL_ttf/ – EvergreenTree
Действительно, когда вы используете Pygame, он поставляется с ним. Я даже установил SDL2, чтобы быть уверенным. Проблема заключается в том, что он говорит: «Ссылка из: /Library/Frameworks/SDL_ttf.framework/Verisons/A/SDL_ttf не найдена», но я могу пойти туда вручную и найти его. – user3791725