Search code examples
pythonsdlpygamesdl-ttf

can not import pygame.font


My OS is OSX 10.8(mountain lion), and I am using python 2.7.3. I thought I had installed pygame successfully. Unfortunately, I was wrong. I am able to import pygame, but there is something wrong when I import pygame.font

>>> import pygame
>>> import pygame.font
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/pygame/font.so, 2): Symbol not found: _TTF_CloseFont
Referenced from: /usr/local/lib/python2.7/site-packages/pygame/font.so
Expected in: flat namespace
in /usr/local/lib/python2.7/site-packages/pygame/font.so

I guess it's a problem with Framework SDL_ttf, but I believe I have installed this framework successfully. I followed this instruction to install pygame, and this is the result of running sudo python config.py

Hunting dependencies...
Framework SDL found
Framework SDL_ttf found
Framework SDL_image found
Framework SDL_mixer found
Framework smpeg not found
PNG     : found
JPEG    : found
SCRAP   : not found
PORTMIDI: not found
Framework CoreMidi found

what should I do to import pygame.font?


Solution

  • I am not able to figure out the solution of this problem, but I have another way to avoid it.

    instead of installing pygame with the way I mentioned in the question, I decided to use the following way to install it. Fortunately, everything works well now. I also highly recommend the guys who want to install pygame using the following approach.

    1. install python from python.org: http://www.python.org/ftp/python/2.7.3/python-2.7.3-macosx10.6.dmg

    this version of python is required by pygame. you must install this version but any version else!! this .dmg file will install python in the following path: /Library/Frameworks/Python.framework/Versions/2.7/

    if there is not something wrong, the .dmg file will add this path to your .bash_profile automatically. if it doesn't do it for you, just edit your .bash_profile and add the following lines to it:

    PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
    export PATH
    

    open a new bash, and use which python to check the version of python you are using. if the version you are using is the above one, you are good to do step 2.

    2. download pygame1.9.1 from pygame.org: http://pygame.org/ftp/pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg and install it.

    3. pygame only supports 32-bit, which means you have to run your pygame with 32-bit python. fortunately, it's easy to use 32-bit python: python2.7-32 your_pygame.py