33

I'm getting what seems to be a common error running the Kivy hello world program. I've tried the solutions I've seen here: manually install gstreamer, adding it to PATH and installing PySDL2. My OS is Windows 7, all other version info is in the error log.

# you need this two lines:
import os
os.environ['KIVY_IMAGE'] = 'pil,sdl2'

#kivy program
from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
    def build(self):
        return Button(text='Hello World')

TestApp().run()

The error log:

[INFO              ] [Logger      ] Record log in C:\Users\xyz\.kivy\logs\kivy_16-11-19_11.txt
[INFO              ] [Kivy        ] v1.9.1
[INFO              ] [Python      ] v2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)]
[INFO              ] [Factory     ] 179 symbols loaded
[INFO              ] [Image       ] Providers: img_pil, img_sdl2 (img_tex, img_dds, img_ffpyplayer, img_gif ignored)
[INFO              ] [Text        ] Provider: sdl2
[INFO              ] [OSC         ] using <thread> for socket
[INFO              ] [Window      ] Provider: sdl2
[INFO              ] [GL          ] GLEW initialization succeeded
[INFO              ] [GL          ] OpenGL version <3.1.0 - Build 8.15.10.2538>
[INFO              ] [GL          ] OpenGL vendor <Intel>
[INFO              ] [GL          ] OpenGL renderer <Intel(R) HD Graphics Family>
[INFO              ] [GL          ] OpenGL parsed version: 3, 1
[INFO              ] [GL          ] Shading version <1.40  - Intel Build 8.15.10.2538>
[INFO              ] [GL          ] Texture max size <8192>
[INFO              ] [GL          ] Texture max units <16>
[INFO              ] [Shader      ] fragment shader: <No errors.>
[INFO              ] [Shader      ] vertex shader: <No errors.>
[INFO              ] [Shader      ] program: <No errors.>
[CRITICAL          ] [Window      ] Unable to find any valuable Window provider at all!
sdl2 - AttributeError: tobytes
  File "C:\Program Files\python27\lib\site-packages\kivy\core\__init__.py", line 67, in core_select_lib
    cls = cls()
  File "C:\Program Files\python27\lib\site-packages\kivy\core\window\window_sdl2.py", line 138, in __init__
    super(WindowSDL, self).__init__()
  File "C:\Program Files\python27\lib\site-packages\kivy\core\window\__init__.py", line 722, in __init__
    self.create_window()
  File "C:\Program Files\python27\lib\site-packages\kivy\core\window\window_sdl2.py", line 255, in create_window
    super(WindowSDL, self).create_window()
  File "C:\Program Files\python27\lib\site-packages\kivy\core\window\__init__.py", line 897, in create_window
    self.render_context = RenderContext()
  File "kivy\graphics\instructions.pyx", line 756, in kivy.graphics.instructions.RenderContext.__init__ (kivy\graphics\instructions.c:10729)
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\__init__.py", line 512, in __init__
    self.filename = arg
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\__init__.py", line 700, in _set_filename
    mipmap=self._mipmap, nocache=self._nocache)
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\__init__.py", line 430, in load
    im = loader(filename, **kwargs)
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\__init__.py", line 198, in __init__
    self._data = self.load(filename)
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\img_pil.py", line 101, in load
    return list(self._img_read(im))
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\img_pil.py", line 86, in _img_read
    img_tmp.mode.lower(), img_tmp.tobytes())
  File "C:\Program Files\python27\lib\site-packages\PIL\Image.py", line 514, in __getattr__
    raise AttributeError(name)

[CRITICAL          ] [App         ] Unable to get a Window, abort.
 Exception SystemExit: 1 in 'kivy.properties.dpi2px' ignored
[CRITICAL          ] [App         ] Unable to get a Window, abort.
2

7 Answers 7

55

In cmd go to python34 and then to Scripts and install the following:

pip install --upgrade pip wheel setuptools
pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew
pip install kivy.deps.gstreamer
pip install kivy.deps.angle
pip install kivy
4
  • 1
    For the people that run into this like me: the pip install pypiwin32 can give an error because pywin32 is possibly already installed and cannot be uninstalled. For me it workend when i ran the items in the second line via a seperate pip install and ignore the pypiwin32 install error.
    – Joris
    Mar 15, 2020 at 13:54
  • 1
    FYI For people out there, this great answer seems also applied for other versions of python. Working well in python 3.7.3
    – Hzz
    Mar 27, 2020 at 12:44
  • Did not worked for me, Windows 10 and Python 3.8.6 installing Kivy as is said in this post.
    – user171780
    Nov 24, 2020 at 10:56
  • @user171780 You should downgrade your python to 3.7. PyInstaller does not work properly with 3.8
    – Elessar
    Jun 2, 2021 at 21:58
10

Try putting <python dir>\share\sdl2\bin to your path, it should do the trick. The thing is that it can't find the sdl2 binary it works with. There probably even isn't any PIL window provider, so using environment variable won't do a thing for creating a window (it'll be used as an image provider though).

I'm not really familiar with PySDL2, so I can't help you with that, however I made an installer for Kivy on Windows to make things easier for beginners.

There are basically two ways you'll end up with anyway:

  1. You'll put the bin folders to a PATH variable permanently

    I consider it really stupid unless you're sure you won't delete Python or the folder, otherwise you'll have a ghost folder in PATH + all other programs will have an access to files in bin folders via PATH

  2. You'll have a batch file that does that temporarily

    Only programs ran from the console/batch will have an access to the bin folder.

The installer does that for you and in fact does even installing from scratch (no Python) or many other things.

In case you haven't installed the Kivy dependencies, please do it first.

2
  • 1
    I'll try and report back. I no longer think I need PySDL2, as kivy.deps.sdl2 is a dependency.
    – foosion
    Nov 19, 2016 at 22:44
  • If your using Anaconda C:\Users[USER NAME]\Anaconda2\share\gstreamer\bin
    – lit
    May 6, 2017 at 21:43
5

Not sure about Windows or Linux, but on python-for-android at the very top you need to put:

#qpy:kivy
import kivy
kivy.require('1.10.1') # replace with your current kivy version !
1
  • Line 1. #qpy:kivy line 2. import kivy line 3. kivy.require('1.10.0'), for me just pip install kivy did all the needed upgrades automatically. the glory of qpython Aug 19, 2017 at 12:58
3

Disable the 3D acceleration and the 2D video acceleration in the display settings of the virtual software (aka vmbox, vmware). I think this will work for you , it works for me after lots of tries.

3
  • 1
    I also got it to work by installing pygame from pip. pip3 install pygame and then it worked, I didn't have to disable 3D acceleration in my VM.
    – james-see
    Aug 14, 2018 at 10:52
  • 1
    @jamescampbell installing pygame solved my problem you could create an answer (instead of just a comment since it is one of viable solutions)
    – Tim
    Apr 5, 2022 at 11:00
  • @Tim good point. Doing that now.
    – james-see
    Apr 5, 2022 at 15:58
3

I just found a quick fix

  1. Once you have installed Kivy using pip
  2. navigate to C:\Users\(accountname)\.kivy\ and open the config.ini file
  3. change the multisamples = 0 from = 2 then restart your computer. This will save other issues too like

[CRITICAL] [GL ] Minimum required OpenGL version (2.0) NOT found!

This worked for me on windows 7 64 bit, python3.5(32 bit) with Kivy version 1.10.0

3

I'm using windows 10 and python 3.6, and I installed kivy using pip. None of above solution helped, but then I uninstall the kivy with pip, and install kivy again with conda according to https://kivy.org/doc/stable/installation/installation-windows.html#installation and it worked.

The packages conda installed for me are: The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
freetype-2.8.1             |           vc14_0         469 KB  conda-forge
sdl2_mixer-2.0.4           |       h6538335_0          83 KB  conda-forge
sdl2-2.0.10                |       h6538335_0         4.3 MB  conda-forge
kivy-1.11.1                |   py36hbc14df2_0        20.2 MB  conda-forge
sdl2_image-2.0.2           |                0         293 KB  conda-forge
glew-2.0.0                 |    he025d50_1002         722 KB  conda-forge
sdl2_ttf-2.0.14            |       h8909db8_1          25 KB  conda-forge
smpeg2-2.0.0               |       h6538335_1         131 KB  conda-forge
------------------------------------------------------------
1
  • Yeah man, thanks a lot! This was the problem for me! :)
    – Marc Vana
    Jul 29, 2020 at 10:52
3

I got this to work by installing pygame from pip.

pip3 install pygame and then it worked.

That way, I didn't have to disable 3D acceleration in my VM.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.