转载一篇文章 python程序在安卓手机上使用
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
return Button(text="Hello,kivy")
TestApp().run()
输出结果:
[INFO ] [Logger ] Record log in C:\Users\usth1\.kivy\logs\kivy_17-06-09_17.txt
[INFO ] [Kivy ] v1.10.0
[INFO ] [Python ] v3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [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: 找不到指定的模块。
File "C:\Users\usth1\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\usth1\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\usth1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\utils.py", line 496, in __get__
retval = self.func(inst)
File "C:\Users\usth1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\metrics.py", line 174, in dpi
EventLoop.ensure_window()
File "C:\Users\usth1\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.
------------------
(program exited with code: 1)
请按任意键继续. . .
接着我在GitHub上查询了相关文档:
https://github.com/kivy/kivy/issues/3889
下载了kivy.deps.sdl2:
C:\Users\usth1>pip install kivy.deps.sdl2
输出结果:
[INFO ] [Logger ] Record log in C:\Users\usth1\.kivy\logs\kivy_17-06-09_16.txt
[INFO ] [Kivy ] v1.10.0
[INFO ] [Python ] v3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)]
[INFO ] [Factory ] 194 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [OSC ] using <thread> for socket
[INFO ] [Window ] Provider: sdl2
[CRITICAL] [Window ] Unable to find any valuable Window provider.
sdl2 - ImportError: DLL load failed: 找不到指定的模块。
File "C:\Users\usth1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\__init__.py", line 67, in core_select_lib
cls = cls()
File "C:\Users\usth1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 140, in __init__
super(WindowSDL, self).__init__()
File "C:\Users\usth1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\__init__.py", line 899, in __init__
self.create_window()
File "C:\Users\usth1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 269, in create_window
self.fullscreen, resizable, state)
File "kivy\core\window\_window_sdl2.pyx", line 110, in kivy.core.window._window_sdl2._WindowSDL2Storage.setup_window (kivy\core/window\_window_sdl2.c:2466)
File "kivy\graphics\cgl.pyx", line 52, in kivy.graphics.cgl.cgl_get_backend_name (kivy\graphics\cgl.c:3044)
File "kivy\graphics\cgl.pyx", line 60, in kivy.graphics.cgl.cgl_get_backend_name (kivy\graphics\cgl.c:2879)
File "C:\Users\usth1\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
File "<frozen importlib._bootstrap>", line 560, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
[CRITICAL] [App ] Unable to get a Window, abort.
Exception ignored in: 'kivy.properties.dpi2px'
Traceback (most recent call last):
File "C:\Users\usth1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\utils.py", line 496, in __get__
retval = self.func(inst)
File "C:\Users\usth1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\metrics.py", line 174, in dpi
EventLoop.ensure_window()
File "C:\Users\usth1\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.
------------------
(program exited with code: 1)
请按任意键继续. . .
成功!
原链接 https://blog.csdn.net/qq_36751365/article/details/72955956