0

import kivymd success.

from kivymd.app import MDApp fail.

sdl2 - ImportError: DLL load failed: Le module spécifié est introuvable.

And I can't "catch this Exception" with:

try:
    from kivymd.app import MDApp
except Exception as e:
    print(e)

Why am I not blocked on the big import ?

Why can't I catch this Exception ?

What should I do to prevent this kind of error ?

Should I create a ticket in the kivymd Github repository ? (if a library need dependencies, the library should download it itself by default no ?)

  • This doesn't look like a standard exception so that would explain the not being able to catch it. – Kraay89 Dec 21 '20 at 14:29
  • Does this answer your question? [sdl2 - ImportError: DLL load failed: The specified module could not be found and \[CRITICAL\] \[App\] Unable to get a Window, abort](https://stackoverflow.com/questions/49482753/sdl2-importerror-dll-load-failed-the-specified-module-could-not-be-found-and) – Kraay89 Dec 21 '20 at 14:29
  • I saw this post but I haven't the same question. It's more about "why there is an ImportError that I can't catch !!!" and what to do in this kind of scenario ! What to do when this is not a standart exception ? Because kivymd has multiples exceptions (widget creation by example) that I can't catch and I'm wondering why and what can I do ? –  Dec 21 '20 at 14:37

1 Answers1

0
  • Why am I not blocked on the big import ?

Because kivy could use some lazy loading and the main import could not trigger all the submodules

  • Why can't I catch this Exception ?

You can catch that exception as following:

try:
    from kivymd.app import MDApp
except ImportError as ie:
    print(ie)
  • What should I do to prevent this kind of error ?

Kivy is not a pure Python framework and rely on several external modules, such as SDL. Thus, depending on your operative system, you have to install that library.

  • Should I create a ticket in the kivymd Github repository ? (if a library need dependencies, the library should download it itself by default no ?)

Not necessarily. That dependency is from kivy itself and not directly kivymd, that obviously depends on kivy. I suggest you to check the installation methods of kivy: doc

MircoT
  • 185
  • 1
  • 9
  • Thanks for the quick answer, I tried the ImportError, it doesn't work too, if Exception doesn't work, I think no exception can be handle ? (but I tried) so why kivy doesn't import it then ? I will check out but I don't understand yet why they doesn't do it. –  Dec 21 '20 at 14:43
  • This confirms that the problem is your installation of Kivy that is missing the sdl2 library. The ImportError works only whithin Python modules, not for external libraries. Try to reinstall the Kivy framework and see if the basic example on their website is working. – MircoT Dec 21 '20 at 15:04