简体   繁体   English

使用Pygame而不安装

[英]Using Pygame without installing

I'm making a real simple RPG game at college and I would like to use pygame. 我正在大学里制作一个真正简单的RPG游戏,我想使用pygame。 However, my college has a group policy disabling any Windows executables from running so I can't install pygame. 但是,我的学院有一个组策略禁用任何Windows可执行文件,因此我无法安装pygame。 Is there any way I can just import pygame by just having it in the same folder? 有没有什么办法可以通过将pygame放在同一个文件夹中来导入pygame?

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 }. 我对外部python库做的一件事是下载源代码,构建它并将构建的库复制到$ { PROJECT_HOME } / lib / $ { EXTERNAL_LIB_NAME }。 This way, I can run my python scripts with just standard python installation on a machine. 这样,我可以在机器上运行标准的python安装我的python脚本。 To be able to use the external lib, you'll have to include the lib directory to sys path like this: 为了能够使用外部lib,您必须将lib目录包含在sys路径中,如下所示:

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

PS: Since pygame has C/C++ files to be compiled, you'd have to use mingw instead. PS:由于pygame有要编译的C / C ++文件,所以你必须使用mingw。 Refer to this answer for that: error: Unable to find vcvarsall.bat 请参考以下答案: 错误:无法找到vcvarsall.bat

EDIT : In case you're wondering how to build pygame from source, you'll need to run setup.py build . 编辑 :如果你想知道如何从源代码构建pygame,你需要运行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. 这将把python库构建到包目录的'build'文件夹中,你会看到它应该如何放在Python的目录中。 You will face the compilation problem in Windows as I've mentioned before, but you can easily fix that. 如前所述,您将面临Windows中的编译问题,但您可以轻松解决这个问题。

EDIT 2 : Download link to contents of 'lib' for PyGame: 编辑2 :下载PyGame的'lib'内容链接:

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

如果你允许从USB驱动器运行东西,一种选择是使用Portable Python 2.7.3.2 ,其中包括PyGame 1.9.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM