1

我正在尝试在 Eclipse IDE 中使用用于 python 的 Kivy 库。我已经尝试了一些我在谷歌上找到的解决方案,但它们似乎都不起作用。我正在使用带有 python 2.7 的 Mac OSX 10.7。

我已经使用命令安装了 kivy setup.py 文件

python setup.py install

我现在如何在 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ 中创建一个 kivy 文件夹。在 Eclipse 中,我转到 Preferences->PyDev->Interpreter 并在其中添加库我添加该路径并应用更改。在编写 python 代码时,我现在可以毫无错误地从 kivy 导入我需要的所有内容,并使用 kivy 模块编写代码完成代码。当我尝试使用代码运行项目时,

import kivy
from kivy.app import App
from kivy.uix.widget import Widget

class PongGame(Widget):
    pass

class PongApp(App):
    def build(self):
        return PongGame()


if __name__=='__main__':
    PongApp().run()

我得到错误,基维python错误

如何设置 Eclipse,以免出现此错误,并且可以直接从 Eclipse 运行 Kivy 程序?

4

2 回答 2

1

在最近的Google Groups 帖子中,Russell Owen 概述了他如何为 Mac OS X 10.6 (Snow Leopard) 构建 64 位版本的PyGame 1.9.1,并且还提供了预构建的 64 位 PyGame OS X 二进制文件的 URL dmg文件!

pygame-1.9.1release-py2.7-python.org-macosx10.6.dmg

罗素的指示是:

Building pygame 1.9.1 on Mac OS X 10.6 using XCode 3.2.6
2012-04-12
I was building this for a binary distribution that would run against python.org's 64-bit Python 2.7.2, for use on Mac OS X 10.6 and later.

* Install dependencies:

- libjpeg (use ./configure, make, sudo make install)
- SDL and extra packages (use precompiled framework builds):
  - SDL
  - SDL_mixer
  - SDL_image
  - SDL_ttf
- portmidi (use CMake as per the instructions)

* Delete shared libraries in /usr/local/lib (if you want to build a binary installer that can be used elsewhere).

* Check for /usr/local/lib/portmidi.a and if not found, make it a symlink from /usr/local/lib/portmidi_s.a or whatever portmidi got installed.

* Modify config_darwin.py to include '/usr/X11/include' and '/usr/X11/lib':
    incdirs = ['/usr/X11/include', '/usr/local/include']
    libdirs = ['/usr/X11/lib/', '/usr/local/lib']

(since libpng and libfreetype are standard in /usr/X11)

* Configure pygame and make sure it finds everything:

python config.py

As of 2012-04-12 on Mac OS X 10.6 I found that png was NOT found. I have no idea why, but I went ahead and installed it manually.

Also SCRAP is not found, but apparently that is normal for Mac OS X.

* Build pygame normally

python setup.py build
bdist_mpkg (or sudo python setup.py install if you don't want a binary installer)

希望这些说明适用于更新版本的 OS X 和 XCode(如果可以,请告诉我们)。

谢谢

于 2013-01-07T11:42:51.647 回答
0

查看输出中的导入错误,您似乎需要安装 pygame 和 PIL。

pygame 安装看起来很棘手,但有一个使用 homebrew 安装 pygame 的指南:

https://bitbucket.org/pygame/pygame/issue/82/homebrew-on-leopard-fails-to-install#comment-627494

如果您安装了 Xcode,理论上您应该能够执行“easy_install PIL”或“pip install PIL”(如果您正在使用分发)。

于 2012-12-05T23:31:56.070 回答