我尝试部署一个 android 应用程序。我在 python 中使用 kivy 框架和 buildozer。我的问题是包含熊猫库。这是我简单且有效的测试代码:
from kivy.app import App
from kivy.uix.label import Label
import kivy
kivy.require('1.11.1')
import pandas as pd
class TestLibraries(App):
def build(self):
df = pd.DataFrame()
df.loc[0, 'text'] = 'this is pandas'
return Label(text = df.loc[0, 'text'])
if __name__ == '__main__':
TestLibraries().run()
下一步是定义 buildozer .spec 文件。在这里我看到两个选项:
- 通过要求:所以我像这样修改 .spec 文件
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy==1.11.1,pandas
这很好用。2. 通过食谱:我从github获取食谱。并将其放入我的名为 recipe 的文件夹中。之后我像这样修改.spec文件
# (str) The directory in which python-for-android should look for your own build recipes (if any)
p4a.local_recipes = /PATH_TO_FOLDER/recipe/
在 buildozer 日志文件中,我可以阅读:
Listing '/PATH_TO_FOLDER/.buildozer/android/app/recipe/pandas'...
Compiling 'PATH_TO_FOLDER/.buildozer/android/app/recipe/pandas/__init__.py'...
因此 buildozer 找到了配方,但未安装该库并且该应用程序无法正常工作。
问题是:为什么不呢?
您可能会要求我使用第二个选项,因为第一个选项效果很好。下一步我想写一个新的食谱。所以我必须学习如何正确地包含现有的食谱。
我希望你能理解我的问题并给一些建议。
谢谢卡帕