sdl2 - ImportError: DLL load failed: The specified module could not be found and [CRITICAL] [App] Unable to get a Window, abort
Asked Answered
V

7

21
  • Python: 3.6.4
  • OS: Windows 10
  • Kivy: 1.10.0

Kivy Installation Method

python -m pip install --upgrade pip wheel setuptools
python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew
python -m pip install kivy.deps.gstreamer
python -m pip install kivy.deps.angle
python -m pip install kivy
python -m pip install kivy_examples
python -m pip install Pillow
python -m pip install cython
python -m pip install PyEnchant

Description

Hi, I am trying to run the example code from the install Kivy. The following is the error I receive back. Any help would be great. I have tried looking at previous enquiries about similar problems, but nothing suggested on them has worked so far.

[INFO   ] [Logger      ] Record log in C:\Users\DoddJ\.kivy\logs\kivy_18-03-26_52.txt
[INFO   ] [Kivy        ] v1.10.0
[INFO   ] [Python      ] v3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pil, img_gif (img_sdl2, img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: pil(['text_sdl2'] ignored)
[CRITICAL] [Window      ] Unable to find any valuable Window provider.
sdl2 - ImportError: DLL load failed: The specified module could not be found.
    File "C:\Users\dev.DoddJ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\__init__.py", line 59, in core_select_lib
fromlist=[modulename], level=0)
    File "C:\Users\dev.DoddJ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 26, in <module>
from kivy.core.window._window_sdl2 import _WindowSDL2Storage

[CRITICAL] [App         ] Unable to get a Window, abort.
  Exception ignored in: 'kivy.properties.dpi2px'
  Traceback (most recent call last):
    File "C:\Users\dev.DoddJ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\utils.py", line 496, in __get__
      retval = self.func(inst)
    File "C:\Users\dev.DoddJ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\metrics.py", line 174, in dpi
      EventLoop.ensure_window()
    File "C:\Users\dev.DoddJ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\base.py", line 127, in ensure_window
      sys.exit(1)
SystemExit: 1
[CRITICAL] [App         ] Unable to get a Window, abort.

Code and Logs

Code that I am trying to run:

import kivy
kivy.require('1.10.0') # replace with your current kivy version !

from kivy.app import App
from kivy.uix.label import Label


class MyApp(App):

    def build(self):
        return Label(text='Hello world')


if __name__ == '__main__':
    MyApp().run()
Valentinavalentine answered 26/3, 2018 at 1:28 Comment(4)
It looks like there's an issue with your sdl installation, can you try it without kivy.deps.sdl2?Excitement
Are you getting this error when running the Kivy app via PyCharm IDE?Leukorrhea
To run it without 'kivy.deps.sdl2' the import error goes away, however I still get the error about being unable to find a window, abort. Yes this is trying to run it in PyCharmValentinavalentine
Please refer to the solution at kivy-error-python-2-7-sdl2-import-errorLeukorrhea
S
44

I had the same problem. I solved this by removing Kivy and its dependencies first.

python -m pip uninstall kivy

python -m pip uninstall kivy.deps.sdl2

python -m pip uninstall kivy.deps.glew

python -m pip uninstall kivy.deps.gstreamer

python -m pip uninstall image

Now reinstalling everything except gstreamer.

python -m pip install --upgrade pip wheel setuptools

python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew --extra-index-url https://kivy.org/downloads/packages/simple/

python -m pip install kivy

It solved the error. Credits to Ben R's Answer.

Sabulous answered 9/7, 2018 at 8:46 Comment(3)
Just adding the second line (install docutils,pygments,etc) without uninstalling kivy and it still works.Octant
Thanks, It was resolved! I command *.py not in pycharm but in python console, and it resolved... maybe pycharm error(or env setting error)?Greenbrier
Thanks a lot, now I can finally run my application.Annalisaannalise
L
5

07-2021, Python 3.9

The problem is that the PATH variable has not been set (Python installation from the Windows Store).

**from the windows menu/browser:

remove program

at the beginning remove any python installation, this will make life easier**

It is best to download python from python.org and install as ADMINISTRATOR as "CUSTOM" with a known path (for all users) IE c:/programs/python39

Be sure to check:

add to PATH variable to system

Now, after installing python - we log out and log back in. Then in the start menu look for CMD and run !!! as administrator

From the admin position, install as stated on the website: https://kivy.org/doc/stable-1.10.1/installation/installation-windows.html

ie:

python -m pip install --upgrade pip wheel setuptools
python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew
python -m pip install kivy.deps.gstreamer

python -m pip install kivy.deps.angle

and finally

python -m pip install kivy

and that solves the whole problem.

Ps. Ifyou write angin command IE:

    python -m pip install kivy.deps.angle

Location of files should be show as IE:

c:/programs/python39....

But not as your home directory

(But it will be if you run cmd as normal user...and then IT doesen't work.... But if you have all files on your home directory YOU HAVE TO REMOVE ALL BEFORE YOU START:

python -m pip uninstall docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew

And then (as admin): python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew

Lamelliform answered 18/7, 2021 at 19:47 Comment(1)
I think the Python installation from the windows store was the main issue for me, thanks for that note! I think i also had just screwed up my system majorly as I had tried to install Python so many times from so many places trying to get this working. Eventually I just wiped my computer to have a fresh start, then used pyenv to download the specific version of Python I needed. Then the normal Kivy install instructions worked out.Hammurabi
W
1

I had the very same problem, and for me the solution was to make use of virtualenv instead of venv. This forces Kivy to use a specific installation of Python.

  1. Download and install Python 3.7, since 3.8 doesn't seem to be supported yet (https://www.python.org/downloads/release/python-376/)

  2. Install virtualenv if not already installed

    pip install virtualenv

  3. Create a virtual environment, specifying the path to the newly installed Python version

    virtualenv --python=C:\path\to\Python37\python.exe my_venv

  4. Activate the new virtual environment

    my_venv/Scripts/activate.bat

  5. Install kivy according to Javapocalypse's answer

    python -m pip install --upgrade pip wheel setuptools
    
    python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew extra-index-url https://kivy.org/downloads/packages/simple/
    
    python -m pip install kivy
    
Witcher answered 26/2, 2020 at 6:18 Comment(1)
dont't install python from Windows Store; ; remove all; then - install from python.org, log out and log in, then: CMD: python -m venv venv @ and@ venv/Scripts/activate @and@ python -m pip install kivy ... TADA :)Lamelliform
C
1

I got the same problem with Python 3.9.1.

Reinstallation of kivy.deps.sdl2, kivy.deps.glew, kivy in the default user mode didn't work for me.

Then I found this comment, which suggested to install these packages in admin mode. It works. https://github.com/kivy/kivy/issues/5677#issuecomment-389990608

Charge answered 3/1, 2021 at 17:0 Comment(0)
S
0

Sir please use venv I got the same error but I solves it using venv. Please create a virtualenv and install using your installation process. It works

Setback answered 5/12, 2020 at 5:52 Comment(0)
U
0

Keep your main file name main.py otherwise, it will raise this error. (Check this before doing anything).

Undertrump answered 2/2, 2021 at 10:38 Comment(1)
I don't think the name of the .py file has anything to do with this. Changing it to main.py didn't change anything, and the message is talking about finding a window provider anyway, not being unable to find the .py file itself.Uproar
P
0

If you enable debug logging (-d) you get more details:

Failed trying to import the "sdl2" provider from "PROJECT\venv\lib\site-packages\kivy\core\window\_window_sdl2.cp37-win_amd64.pyd". This error is often encountered when a dependency is missing, or if there are multiple copies of the same dependency dll on the Windows PATH and they are incompatible with each other. This can occur if you are mixing installations (such as different python installations, like anaconda python and a system python) or if another unrelated program added its directory to the PATH. Please examine your PATH and python installation for potential issues. To further troubleshoot a "DLL load failed" error, please download "Dependency Walker" (64 or 32 bit version - matching your python bitness) from dependencywalker.com and set the environment variable KIVY_SDL2_DEPENDENCY_WALKER to the full path of the downloaded depends.exe file and rerun your application to generate an error report

Using Dependency Walker shows PYTHON37.DLL as what was missing.

I suspect that a traditional system installation of Python must be used, and not one from the Microsoft Store. The Store versions don't appear to have the DLLs anywhere. Though I've not had any problems with native dependencies until now.

I also tried building from source instead of using the wheel, but --no-binary=kivy.deps.sdl2 results in:

ERROR: Could not find a version that satisfies the requirement kivy-deps.sdl2~=0.3.1; sys_platform == "win32" (from kivy) (from versions: none)
ERROR: No matching distribution found for kivy-deps.sdl2~=0.3.1; sys_platform == "win32"

Piranesi answered 14/12, 2021 at 14:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.