MacBook Python Pygame Anaconda – issues

This post is to help you troubleshoot some issue you might find while installing PYGAME.

Before we start, I use Mac OS  and Python 2.7.11 |Anaconda custom (x86_64)

SDS-bash3.2$ conda --version
conda 4.2.9
SDS-bash3.2$ which anaconda
/Users/sampathkumarm/anaconda/bin/anaconda
SDS-bash3.2$ anaconda --version
anaconda Command line client (version 1.4.0)

Note: My bash prompt looks like this

SDS-bash3.2$

How did I come to know these Pygame installation errors?

As a part of my smart car project completion, we are required to install Pygame. If you are also doing similar work, I would recommend following steps

Step1: Update number of trails runs to 2 in agent.py

Step2: run agent.py

SDS-bash3.2$ python agent.py > log
SDS-bash3.2$ head log

In case no error message are found are seen in the log then it’s good. You should also get Pygame UI for simulation if there are no error.

Step3:  In case you see errors in the log. Try to install Pygame using anaconda

SDS-bash3.2$ conda install pygame

As a part project completion, you need Pygame. So while installing Pygame using conda I had this following error

Error: from pygame.base import * ImportError: dlopen
.....
...SDL Error - missing/usr/local/lib/libSDL-1.2.0.dylib...
....
Pygame installation – First problem – SDL Error – missing/usr/local/lib/libSDL-1.2.0.dylib

From the error messages what I understood is SDL related one file is missing (/usr/local/lib/libSDL-1.2.0.dylib).  As I searched about I came to know that it is Simple Media Direct Layer  and it is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D

Here is the solution that worked for me

SDS-bash3.2$ pip install pygame

 

Checking if Pygame installed

SDS-bash3.2$ python
Python 2.7.11 |Anaconda custom (x86_64)| (default, Dec 6 2015, 18:57:58)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import pygame
>>>

Pygame is imported !! Yahoooooooo 🙂

 

Pygame installation – Second problem -[Pygame libpng]

While working with Pygame I found that it is not able to read images and was throwing error like libpng is not able to read image.

pygame.error: Failed loading libpng.dylib: dlopen(libpng.dylib, 2): image not found

 

Here is how I fixed/installed it.

SDS-bash3.2$ brew install libpng
==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.19.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libpng-1.6.19.mavericks.bottle.tar.gz
🍺 /usr/local/Cellar/libpng/1.6.19: 17 files, 1.3M

 

First time when I tried above command, I was having lots of file path permission. Lots of brew folders are having permission for root and I did not know. So after random browsing, I found this command to try.

SDS-bash3.2$ brew doctor

This will tell you all possible issues or reasons if you could not install using brew.

If you see any file path permission issue please fix them and once no more files permission issue are there then proceed to installing libpng.

Wise it would, if you don’t try to fix every problem that brew doctor shows.

References:

 

Hope this helps!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s