我使用pip安装了kivi,pyjnius和jnius

python.exe -m pip install pyjnius
python.exe -m pip install jnius

它已成功构建并安装。

我尝试运行以下示例之一:
'''
Compass example


This example is a demonstration of Hardware class usage.
But it has severals drawbacks, like using only the magnetic sensor, and
extrapolating values to get the orientation. The compass is absolutely not
accurate.

The right way would be to get the accelerometer + magnetic, and computer
everything according to the phone orientation. This is not the purpose of
this
example right now.

You can compile it with::

./build.py --package org.test.compass --name compass \
    --private ~/code/kivy/examples/android/compass \
    --window --version 1.0 debug installd
'''


import kivy
kivy.require('1.7.0')

from jnius import autoclass
from kivy.app import App
from kivy.properties import NumericProperty
from kivy.clock import Clock
from kivy.vector import Vector
from kivy.animation import Animation

Hardware = autoclass('org.renpy.android.Hardware')


class CompassApp(App):
.
.
.

并得到错误:
[INFO   ] [Logger      ] Record log in C:\Users\Janka\.kivy\logs\kivy_18-06-
03_2.txt
[INFO   ] [Kivy        ] v1.10.0
[INFO   ] [Python      ] v3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18)
[MSC v.1900 32 bit (Intel)]
Traceback (most recent call last):
File "C:\Users\Janka\AppData\Local\Programs\Python\Python35-32\share\kivy-
examples\android\compass\main.py", line 25, in <module>
 from jnius import autoclass
File "C:\Users\Janka\AppData\Local\Programs\Python\Python35-32\lib\site-
packages\jnius\__init__.py", line 12, in <module>
 from .jnius import *  # noqa
ImportError: DLL load failed: The specified module could not be found.

我究竟做错了什么?我是新手,只是尝试使它在给定的示例中起作用。也许我需要在运行之前对其进行编译?

最佳答案

我不确定您的pyjnius是否正确编译。但是,更大的问题是您的pyjnius代码只能在Android上运行-org.renpy.android.Hardware在桌面上不存在。

pyjnius通常就是这种情况,尽管它可以在桌面上运行,但是如果您只需要Android平台的话,将它放在那里并没有多大意义。通常,只有在Android上运行时,我通常通过有条件地导入和使用pyjnius来解决此问题。

关于python - pyjnius导入错误?运行kivy的示例android程序期间的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50664124/

10-10 00:37