0

when i run a simple python kivy code i get this that shows down below i get Unable to get a Window, abort error. The code :

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

class MyApp(App):
    def build(self):
        return Label(text="sinai cpa")

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

the error:

[INFO   ] [Logger      ] Record log in C:\Users\Kfir Sinai\.kivy\logs\kivy_21-04-07_2.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "C:\Users\Kfir Sinai\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\Kfir Sinai\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe"
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pil (img_sdl2, img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: pil(['text_sdl2'] ignored)
[CRITICAL] [Window      ] Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
sdl2 - ImportError: DLL load failed while importing _window_sdl2: The specified module could not be found.
  File "C:\Users\Kfir Sinai\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\kivy\core\__init__.py", line 58, in core_select_lib
    mod = __import__(name='{2}.{0}.{1}'.format(
  File "C:\Users\Kfir Sinai\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\kivy\core\window\window_sdl2.py", line 27, in <module>
    from kivy.core.window._window_sdl2 import _WindowSDL2Storage

[CRITICAL] [App         ] Unable to get a Window, abort.

any help??

2 Answers2

1

I was struggling with the same problem for a couple of days and finally I am not getting that EROR. ( I won't say I figured it out cause I still don't know what was the point of it :) I am using PyCharm , I deleted whole installed kivy modules and my old kivy projects - files. After that I have installed 3.6 version of python (I was using 3.9 version ), I have created a new virtual environment and set the project interpreter to 3.6 version . You should check out that new environment's module stack,there shouldn't be your global python modules and install kivy module using PyCharm's feature. It worked for me after all... So I think it was a kind of conflict between file names and modules or virtual environments but on the top shot I don't have that problem anymore , I hope my solution will work for you or other visitors. Have a good days...

Alp
  • 31
  • 4
0

I don't know if you have solved the problem yet, but i too struggled with this problem and must some problem of dependencies. To solve create a virtual environment

python -m pip install --upgrade pip setuptools wheel virtualenv

python -m virtualenv kivy_venv

If you're on windows cmd shell do

kivy_venv\Scripts\activate

Otherwise do

source kivy_venv/Scripts/activate

A kivy_env folder will be created in your current path; for me it was

F:\Job\Info\Desktop Software development\Kivy>

So kivy_env has been created in kivy folder. And the virtual environment will be activated

Next do (note that to install the new kivy rc2 you need to add --pre to pip)

pip install kivy_deps.glew kivy_deps.sdl2 kivy_deps.gstreamer kivy kivy_examples --pre

Now you if you run your code (Note that the "code file" should be in the same directory where you created the virtual environment, which for my case it was kivy) will work.

If you don't want to use a virtual environment than deactivate your virtual environement

kivy_venv\Scripts\deactivate

And install kivy and all its dependencies

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

After that go to the folder where you installed kivy for the virtual environment. For me it was

F:\Job\Info\Desktop Software development\Kivy\kivy_env\Lib\site-packages\

And copy the "kivy" folder to one of your python paths. Mine was

E:\Programmes\Python\Python39\Lib\site-packages

And copy the "share" folder from "F:\Job\Info\Desktop Software development\Kivy\kivy_env" to one of your python paths. Mine was

E:\Programmes\Python\Python39\

Now if you run your code from anywhere it should work. (The path where you paste the folders should be in

sys.path

Hope that's it work for you.

Thanks to the answers of Javapocalypse Issue, and Issue#6342