I followed following steps to install kivy in virtualenv (Mac OSX) with support of sdl2
$ brew install sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer
$ pip install -I Cython
$ USE_OSX_FRAMEWORKS=0 pip install kivy
but when tried to run basic documentation code
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()
I got following error
[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.
I also tried to give path of sdl2.dylib in KIVY_SDL2_PATH but not getting any result but using kivy.app works fine but I want to use virtualenv
I had a similar error on my new Mac (Sierra). I followed the suggestion at https://github.com/kivy/kivy/issues/4688
and installed the latest version of Kivy using the commandUSE_OSX_FRAMEWORKS=0 pip install https://github.com/kivy/kivy/zipball/master
This worked for me, and Kivy is now using SDL2 and not looking for pygame.
Previously, I either needed pygame, but got errors about a "Windows BMP file" when resizing the window, or if I removed pygame, it didn't find the SDL2 I'd installed with brew.
After much wheel spinning with homebrew, the only thing that worked for me was to use macports to install the dependencies:
sudo port install libsdl2 libsdl2_image libsdl2_ttf libsdl2_mixer
来源:https://stackoverflow.com/questions/39141563/kivy-support-for-sdl2-in-virtualenv