Using Pygame without installing

核能气质少年 提交于 2020-01-11 09:25:10

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/14368246/using-pygame-without-installing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!