10

I've installed pygame with Anaconda using the following command:
conda install --channel https://conda.anaconda.org/kne pygame

Then I tried to import pygame and I got the following error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ejalaa/anaconda/lib/python2.7/site-packages/pygame/__init__.py", line 133, in <module>
from pygame.base import *
ImportError: dlopen(/Users/ejalaa/anaconda/lib/python2.7/site-packages/pygame/base.so, 2): Library not loaded: /usr/local/opt/sdl/lib/libSDL-1.2.0.dylib
Referenced from: /Users/ejalaa/anaconda/lib/python2.7/site-packages/pygame/base.so
Reason: image not found

What does that mean ? Any idea how I can solve it?

Thank you.

ejalaa12
  • 375
  • 3
  • 12
  • Have you checked that the install happened correctly? – Tom Kealy Dec 16 '15 at 14:56
  • Check [this SO question](https://stackoverflow.com/questions/9088051/unable-to-import-pygame) to make sure it's not a 32bit vs. 64bit. issue – vrs Dec 16 '15 at 15:01
  • @TomKealy how do I check that? @vrs running the command `file /usr/bin/python` returns `/usr/bin/python: Mach-O universal binary with 2 architectures /usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/python (for architecture i386): Mach-O executable i386` – ejalaa12 Dec 16 '15 at 23:54

4 Answers4

12

After wasting 2 hours, I realized the culprit is the "conda install" which caused the bad installation.

the solution is simply uninstall it and pip install it:

pip uninstall pygame pip install pygame

Yuchao Jiang
  • 3,522
  • 30
  • 23
7

A. Check if you have a 64 or 32 bit version pygame and make sure your version of python is the same.

B. Use something like pip install or any other type of method to install pygame.

C. Install a previous version of pygame and python, you might have some more luck with that.

The error is basically saying that a class in pygame called image could not be found. Obviously pygame has not been installed properly so I would suggest using the above methods to install it again.

I hope this helps!

ModoUnreal
  • 642
  • 5
  • 15
  • Thank you ! I used method B and installed pygame by following this tutorial: http://www.shodanproductions.com/forum/viewtopic.php?t=67&p=272#p272 Hope it helps others ;) – ejalaa12 Dec 19 '15 at 17:48
6

Similar problem here.

My experience: Used conda install -c https://conda.anaconda.org/quasiben pygame to install 1.9.1.

Then conda uninstall pygame, and pip install pygame (This time 1.9.3, and it works)

Leighton
  • 996
  • 9
  • 4
3

if you are using python 2.7, mac os and conda for package management. You should try this. (I only tested it for python 2.7, but similar approach should work for python 3.x as well)

[optional] if you don't create conda environment yet, you can create one as shown below. Let's assume your conda environment name 'conda-env-p27'

conda create -n conda-env-p27 python=2.7 anaconda

Activate your conda environment. Let's assume your conda environment name 'conda-env-p27'

source activate conda-env

[optional] if you already install pygame with conda, you must uninstall it.

conda uninstall pygame

Then, install pygame with pip package manager. ()

pip install pygame

I had installed pygame with prior to activate conda environment. But, It does not work. But, after activating conda environment, I have install it again with pip and it worked for me.

clockworks
  • 3,755
  • 5
  • 37
  • 46