无需安装即可使用Pygame [英] Using Pygame without installing

查看:108
本文介绍了无需安装即可使用Pygame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在大学里制作一款真正简单的RPG游戏,我想使用pygame.但是,我的大学有一个组策略,禁止所有Windows可执行文件运行,因此我无法安装pygame.有什么办法可以将pygame放在同一个文件夹中?

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?

推荐答案

我对外部python库所做的一件事是下载源代码,对其进行构建,然后将构建的库复制到$ { PROJECT_HOME }中/lib/$ { EXTERNAL_LIB_NAME }.这样,我可以在机器上仅通过标准python安装运行我的python脚本.为了能够使用外部库,您必须将lib目录包含在sys路径中,如下所示:

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 .:由于pygame具有要编译的C/C ++文件,因此您必须改为使用mingw.请参考以下答案:错误:无法找到vcvarsall.bat

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

编辑:如果您想知道如何从源代码构建pygame,则需要运行setup.py build.这会将python库构建到package目录的'build'文件夹中,在那里您将看到如何将其放置在Python目录中.如前所述,您将在Windows中遇到编译问题,但是您可以轻松解决该问题.

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.

编辑2 :下载指向PyGame的"lib"内容的链接:

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

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

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

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

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

这篇关于无需安装即可使用Pygame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆