macos - Virtualenv 中的 Kivy 对 SDL2 的支持

标签 macos python-3.x virtualenv kivy sdl-2

我按照以下步骤在 virtualenv (Mac OSX) 中安装 kivy,并支持 sdl2

$ brew install sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer
$ pip install -I Cython
$ USE_OSX_FRAMEWORKS=0 pip install kivy

但是当尝试运行基本文档代码时

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput


class LoginScreen(GridLayout):

    def __init__(self, **kwargs):
        super(LoginScreen, self).__init__(**kwargs)
        self.cols = 2
        self.add_widget(Label(text='User Name'))
        self.username = TextInput(multiline=False)
        self.add_widget(self.username)
        self.add_widget(Label(text='password'))
        self.password = TextInput(password=True, multiline=False)
        self.add_widget(self.password)


class MyApp(App):

    def build(self):
        return LoginScreen()


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

我收到以下错误

[INFO              ] [Logger      ] Record log in /Users/manthansharma/.kivy/logs/kivy_16-08-25_68.txt
[INFO              ] [Kivy        ] v1.9.1
[INFO              ] [Python      ] v3.5.2 (default, Aug 16 2016, 05:35:40) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]
[INFO              ] [Factory     ] 179 symbols loaded
[INFO              ] [Image       ] Providers: img_tex, img_imageio, img_dds, img_gif (img_pygame, img_pil, img_ffpyplayer ignored)
[CRITICAL          ] [Text        ] Unable to find any valuable Text provider at all!
pygame - ImportError: No module named 'pygame'
  File "/Users/manthansharma/virtualenvs/kivy/lib/python3.5/site-packages/kivy/core/__init__.py", line 59, in core_select_lib
    fromlist=[modulename], level=0)
  File "/Users/manthansharma/virtualenvs/kivy/lib/python3.5/site-packages/kivy/core/text/text_pygame.py", line 12, in <module>
    import pygame

pil - ImportError: No module named 'PIL'
  File "/Users/manthansharma/virtualenvs/kivy/lib/python3.5/site-packages/kivy/core/__init__.py", line 59, in core_select_lib
    fromlist=[modulename], level=0)
  File "/Users/manthansharma/virtualenvs/kivy/lib/python3.5/site-packages/kivy/core/text/text_pil.py", line 8, in <module>
    from PIL import Image, ImageFont, ImageDraw

[CRITICAL          ] [App         ] Unable to get a Text provider, abort.

我还尝试在 KIVY_SDL2_PATH 中给出 sdl2.dylib 的路径,但没有得到任何结果,但使用 kivy.app 工作正常,但我想使用 virtualenv

最佳答案

我在我的新 Mac (Sierra) 上也遇到了类似的错误。 我遵循了https://github.com/kivy/kivy/issues/4688的建议

并使用命令安装最新版本的 Kivy
USE_OSX_FRAMEWORKS=0 pip install https://github.com/kivy/kivy/zipball/master

这对我有用,Kivy 现在使用 SDL2,而不是寻找 pygame。
以前,我要么需要 pygame,但在调整窗口大小时收到有关“Windows BMP 文件”的错误,或者如果我删除了 pygame,它找不到我用brew 安装的 SDL2。

关于macos - Virtualenv 中的 Kivy 对 SDL2 的支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39141563/

相关文章:

python - 动态数组名

python - 从本地 git 存储库访问 Python 包

python - 如何确保只在 virtualenv 中调用 pip?

python - 为什么 pip freeze >requirements.txt 返回权限被拒绝

node.js - 安装node和npm的问题

python - 如何为星形参数设置默认值?

python - MacOS Catalina 上的两种不同的 Python3 和两种不同的 Python2 安装

python - 如何使用Python中的标准分割字符串数据?

python - 在制作 boost.python helloword 演示时不安全地使用相对 rpath libboost.dylib?

macos - dtrace 中的 "dynamic variable drops with non-empty dirty list"是什么意思?