我正在尝试使用kivy和buildozer将用Python编写的代码制作为APK。为了用猕猴桃导入大熊猫,我新创建了自己的食谱(大熊猫)。
pipinv的虚拟环境如下;
% pipenv run pip freeze --all
appdirs==1.4.3
buildozer==0.40.dev0
colorama==0.4.1
Cython==0.28.2
Jinja2==2.10.1
MarkupSafe==1.1.1
numpy==1.16.4
pandas==0.24.2
pep517==0.5.0
pexpect==4.7.0
pip==19.1.1
ptyprocess==0.6.0
python-dateutil==2.8.0
python-for-android==0.7.0
pytoml==0.1.20
pytz==2019.1
setuptools==41.0.1
sh==1.12.14
six==1.12.0
virtualenv==16.6.0
wheel==0.33.4
考虑依赖的tihs配方的init.py如下;
from pythonforandroid.recipe import PythonRecipe
class PandasRecipe(PythonRecipe):
version = '0.24.2'
url = 'https://files.pythonhosted.org/packages/b2/4c/b6f966ac91c5670ba4ef0b0b5613b5379e3c7abdfad4e7b89a87d73bae13/pandas-{version}.tar.gz'
depends = [('python2', 'python2legacy', 'python3', 'python3crystax'), 'numpy', 'pytz', 'dateutil']
site_packages_name = 'pandas'
recipe = PandasRecipe()
也在buildozer.spec中
requirements = python3, kivy, android, setuptools, numpy, pandas
已指定。
main.py和test.kv如下;
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import StringProperty
from kivy.properties import NumericProperty
from kivy.utils import get_color_from_hex
import numpy as np
# import pandas as pd
a = np.array([0, 1, 2])
b = np.array([1, 2, 3])
c = np.array([2, 3, 4])
ab = np.dot(a, b)
bc = np.dot(b, c)
ca = np.dot(c, a)
class TextWidget(Widget):
number = NumericProperty(0)
def buttonClicked(self):
self.number = int(ab)
def buttonClicked2(self):
self.number = int(bc)
def buttonClicked3(self):
self.number = int(ca)
class TestApp(App):
def __init__(self, **kwargs):
super(TestApp, self).__init__(**kwargs)
self.title = "kivy_buildozer"
if __name__ == "__main__":
TestApp().run()
#:import hex_color kivy.utils.get_color_from_hex
TextWidget:
<TextWidget>:
BoxLayout:
orientation: "vertical"
size: root.size
Label:
size_hint_y: 0.9
id: label1
font_size: 300
text: str(root.number)
canvas.before:
Color:
rgba: hex_color("#606060")
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
size_hint_y: 0.1
Button:
id: button1
text: "(0,1,2) * (1,2,3)"
font_size: 40
color: hex_color("#ffffff")
background_color: hex_color("#f1d661")
on_press: root.buttonClicked()
Button:
id: button2
text: "(1,2,3) * (2,3,4)"
font_size: 40
color: hex_color("#ffffff")
background_color: hex_color("#f1d661")
on_press: root.buttonClicked2()
Button:
id: button3
text: "(2,3,4) * (0,1,2)"
font_size: 40
color: hex_color("#ffffff")
background_color: hex_color("#f1d661")
on_press: root.buttonClicked3()
使用buildozer android debug deploy run logcat
构建这些文件时,出现以下错误;
Traceback (most recent call last):
File "setup.py", line 12, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
尽管出现此错误,但我在站点软件包中有pkg_resources(从最新版本的setuptools == 41.0.1中可以看到)。我可以通过从buildozer.spec中删除熊猫来成功构建 。该错误该怎么办?