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?
-
2If you can't get @ViteFalcon's method to work and you're willing to try other packages besides `pygame`, check out `pyglet`, which can be imported without being installed. (If you're using a 64-bit Python, you may need to go with `pyglet` version 1.2, which is currently in alpha.) – John Y Jan 17 '13 at 21:45
2 Answers
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

- 1
- 1

- 6,575
- 3
- 30
- 48
-
1I've never done this before and i cant get this to work. installed mingw and it works fine however I cannot seem to get it to build as it throws an error "RuntimeError: The dependencies are linked to the wrong C runtime for Python 3.2". I really wanted to use pygame but i may have to use pyglet. – megamit Jan 18 '13 at 00:23
-
1pyglet is Python wrappers to OpenGL. If you're looking to build a game, that's a bit low-level. I've updated the answer to include a link to download PyGame for 2.7. Unzip that into 'lib' directory of your project and use it as I've mentioned in the first part of my answer. – Vite Falcon Jan 18 '13 at 05:03
-
2Thank you very much for the download, It works now. I use python 3.2 as you may have guessed and im not sure it matters but your code didn't work. i made it work by fiddling with it to get `from sys import path as syspath syspath.append(syspath[0] + '\\lib')` – megamit Jan 18 '13 at 17:25
-
1@user1985217: Don't forget to accept this answer if it solved your problem, which it looks like it did. – John Y Jan 18 '13 at 17:32
-
@MightyMit: That code was for Python 2.7. It would different for 3.2 :)... Glad that you've got pygame works for you now – Vite Falcon Jan 18 '13 at 22:16
If you're allowed to run stuff from a USB drive, one option would be to use Portable Python 2.7.3.2, which includes PyGame 1.9.1.

- 14,123
- 2
- 48
- 72