3

I ran brew install pygame, it installed it together with all the dependencies. Python v2.7.10 / OS X version 10.11.2

Whenever I import pygame in a script it says this

Traceback (most recent call last):
 File "~/Documents/test.py", line 1, in <module>
import pygame, random, sys
ImportError: No module named pygame

How do I fix this?

2

Have you checked which python are you running - the system python or the one you installed via homebrew? I suspect the first.

As a test, try running

/usr/local/Cellar/python/2.7.10/bin/python

and typing

>> import pygame

If this works, you can make the brew version the default by using:

brew link python
2
  • I hadn't even installed it through homebrew, I didn't see any such requirements when reading about it. But thanks! – DisplayName Jan 6 '16 at 1:40
  • If you're going to install pygame through homebrew, using the homebrew python as well simplifies your life and setup effort greatly. – Chris Jan 6 '16 at 5:46
1

After installing brew install pygame myself, it spit out this message:

==> python -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cellar/pygame/1.9.2a0 --single-version-externally-managed --record=installed.txt
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
  mkdir -p /Users/packrd/Library/Python/2.7/lib/python/site-packages
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/packrd/Library/Python/2.7/lib/python/site-packages/homebrew.pth

which apparently meant "we installed this, but your python won't be able to use it"

The oddness here appears to be that if you do brew install pygame it doesn't install python, just pygame (for dependencies to use?)

So either follow those directions (as printed on your screen) then it works, or do brew install python and use that python instead (/usr/local/bin/python instead of /usr/bin/python).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .