MightyMit MightyMit - 1 month ago 11x
Python Question

Using Pygame without installing

I'm making a real simple RPG game at college and I would like to use pygame. However, my college has a group policy disabling any Windows executables from running so I can't install pygame. Is there any way I can just import pygame by just having it in the same folder?


One thing I do with external python libraries is to download the source, build it and copy the built library into ${PROJECT_HOME}/lib/${EXTERNAL_LIB_NAME}. This way, I can run my python scripts with just standard python installation on a machine. To be able to use the external lib, you'll have to include the lib directory to sys path like this:

import os
from sys import path as syspath
syspath.append(os.path.join(os.path.dirname(__file__), 'lib'))

P.S.: Since pygame has C/C++ files to be compiled, you'd have to use mingw instead. Refer to this answer for that: error: Unable to find vcvarsall.bat

EDIT: In case you're wondering how to build pygame from source, you'll need to run setup.py build. This will build the python library into 'build' folder of the package directory and there you'd see how it should be placed in Python's directory. You will face the compilation problem in Windows as I've mentioned before, but you can easily fix that.

EDIT 2: Download link to contents of 'lib' for PyGame:

Python 2.7: http://dl.dropbox.com/u/71422266/pygame27.7z

Python 3.2: http://dl.dropbox.com/u/71422266/pygame32.7z