Can't use kivy with briefcase on windows
Describe the bug
briefcase dev -d is working well
briefcase run fails
To Reproduce Steps to reproduce the behavior:
- clone https://github.com/jgirardet/kivybriefhello
- create a virtualenv and activate it
- pip install briefcase
- briefcase dev -d => ok
- briefcase run => fail no message
- PS C:\Users\jim\rien\kivybrief\helloworld> & '.\windows\Hello World\src\python\python.exe' -m helloworld
[INFO ] [Logger ] Record log in C:\Users\jim\.kivy\logs\kivy_20-07-15_9.txt
[INFO ] [Kivy ] v1.11.0
[INFO ] [Kivy ] Installed at "C:\Users\jim\rien\kivybrief\helloworld\windows\Hello World\src\\app_packages\kivy\__init__.py"
[INFO ] [Python ] v3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "C:\Users\jim\rien\kivybrief\helloworld\windows\Hello World\src\python\python.exe"
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.1.9
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.1.22
[INFO ] [Factory ] 184 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_gif (img_sdl2, img_pil, img_ffpyplayer 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: Le module spécifié est introuvable.
File "C:\Users\jim\rien\kivybrief\helloworld\windows\Hello World\src\\app_packages\kivy\core\__init__.py", line 63, in core_select_lib
fromlist=[modulename], level=0)
File "C:\Users\jim\rien\kivybrief\helloworld\windows\Hello World\src\\app_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.
Unable to start application 'helloworld'
This a usual error in kivy when missing dependencies. I don't think it's a kivy bug since dev is working well.
I looked at app_packages and every thing seems good.
Environment:
- Operating System: windows 10
- Python version: 3.7
- Software versions:
- Briefcase: 0.3.2
- kivy: 1.11.0 (same thing with 2.0.0rc3)
I'm sorry ,I have no idea at all how to help on it.
Related:
- #1484
Thanks for the report. I definitely want to support Kivy, so if anyone wants to dig into this, feel free. The fact that it works in dev mode means the likely source of the problem will one or more libraries that Kivy is dependent on, or the environment in which Kivy expects to run.
I've flagged this as a Windows bug, since that's the case you've demonstrated here; however I can't rule out that it is broken on other platforms too - followup reports welcome.
I confirm it's a windows only. kivy and briefcase runs on linux
Ok with the help ok kivy maintainers I found the bug. And I'd like your opinion @freakboy3742 on how we could fix it.
So there are on windows kivy_deps ( kivy-deps.glew, kivy-deps.angle, kivy-deps.gstreamer, kivy-deps.sdl2) that are installed in a share directory next to Lib.
The implementation of kivy installer makes it search python\\share but briefcase installs it in app_packages\\share. manually copying share inside python fixes the crash.
so How to solve it ?
- ask kivy maintainer to change it seems not fair ;-)
- change how https://github.com/beeware/briefcase/blob/c09dffcfea53e0e4546abd4d52058313b6473fc3/src/briefcase/commands/create.py#L372 install_app_dependencies work to target "python" for some specific packages. It would need adding new section in
pyproject.tomlor manually maintain thisspeciallist. - A third approach (and clearly my favorite) would be to do it in a post_create script like we discussed in #436. Like this we would add in doc or wiki what need to be added to use briefcase and kivy. This also fixes other fancy install/config that could appear in the futur.
I might have a window to work on this next week (before holidays)
Thanks for doing that research.
The one thing I'm not clear on: why it's looking in python\share? Where is it getting that path from? It seems to me that is the piece that needs to be configured, rather than trying to change Kivy or perform extensive post-processing on the installed artefacts.
Also - when you say the "Kivy installer": what are you referring to? Briefcase operates on the assumption that everything is pip installable - what "Kivy installer" are you referring to?
Lastly - you've missed one possible solution - and one that should be (in theory) a lot simpler: Install libraries in a location other that app_packages. There's nothing special about that path; it's a location that is configured in the template. Personal preference would be to keep the Python install separate from the app packages, but it's at least an option worth considering.
the python\share explication stands in how deps ars inported the explication is here:
https://github.com/kivy/kivy-sdk-packager/blob/1dc843c26026fdd70a44ce682b3110976b0139e7/win/common.py#L214
"kivy isntaller" was a bad word choice, undestand "when importing kivy_deps it looks into share".
About your proposal, I don't see how different it is from my 2nd porposal ?
The key difference with option (2) is that I'm not suggesting a "special handling" list - I'm suggesting changing a complete change to the installation location.
Looking at the Kivy code, though; it looks like using os.add_dll_directory() to add the app_packages/share folder would be an option; we just need to work out where to hook that extra code in.
but how changing the installation location could possibly fix it. I think I'm missing a something here.
The issue is that Kivy is hard-codes the python/share directory based on sys.prefix. Briefcase is causing confusion by installing Kivy in a location other than sys.prefix. If we installed all packages in sys.prefix, rather than using app_packages, this problem wouldn't exist.
ok it's clear enough. But it doesn't protect against another "fancy package installation" which would fail pointing to sys.prefix. And I also think it's better to let 'python' dir "clean". But I don't know why ;-)
We can also delay all of this and just explain in doc what extra steps are needed to run kivy on windows.
Note there is also another trick, the env variable KIVY_NO_CONSOLELOG need to be set on windows to allow use of pythonw.exe
I followed the example and decided to try to copy the windows/Hello World/src/app_packages/share directory into windows/Hello World/src/python/ - meaning I now have the dependencies in both app_packages and python dirs.
After this operation this toy example ran succesfully.
Edit: I used conda environment.
@jgirardet Have you packaged a Kivy app for android using briefcase on Linux? I know that Kivy uses kivy/buildozer with kivy/python-for-android which are similar to briefcase and beeware/Python-Android-Support.
I tried that on Windows and package was built but it crashed.