我的main.py和buildozer.spec要求在这里
# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager,Screen,FadeTransition
from kivy.lang import Builder
from kivy.properties import ObjectProperty, StringProperty
from kivy.core.text import LabelBase
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from kivy.storage.jsonstore import JsonStore
class MainWindow(Screen):
pass
class SecondWindow(Screen):
stored_data = ObjectProperty(None)
def __init__(self,*args,**kwargs):
super(Screen,self).__init__(*args,**kwargs),
self.stored_data = JsonStore('data.json')
def gonder(self):
name = self.ids.name.text
scope = ["https://spreadsheets.google.com/feeds",
'https://www.googleapis.com/auth/spreadsheets',
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)
client = gspread.authorize(creds)
sheet = client.open("verigonder").sheet1
sheet.append_row([name])
class ThirdWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
class mainApp(App):
def build(self):
return Builder.load_file("my.kv")
if __name__ == "__main__":
mainApp().run()
和 buildozer.spec 的要求在这里
requirements = python3,kivy,gspread,oauth2client,google-auth-oauthlib,httplib2,pyasn1,pyasn1-modules,rsa,request,google
和调试日志
06-02 15:25:27.121 25609 25949 I python : Traceback (most recent call last):
06-02 15:25:27.121 25609 25949 I python : File
"/home/ademberkaksoy/sheet/.buildozer/android/app/main.py", line 8, in <module>
06-02 15:25:27.121 25609 25949 I python : File
"/home/ademberkaksoy/sheet/.buildozer/android/platform/build-armeabi-v7a/build/python-
installs/myapp/gspread/__init__.py", line 16, in <module>
06-02 15:25:27.121 25609 25949 I python : File
"/home/ademberkaksoy/sheet/.buildozer/android/platform/build-armeabi-v7a/build/python-
installs/myapp/gspread/auth.py", line 12, in <module>
06-02 15:25:27.121 25609 25949 I python : ModuleNotFoundError: No module named 'google'
06-02 15:25:27.121 25609 25949 I python : Python for android ended.
它仍然给出相同的错误。我需要做什么来修复这种情况?它的工作在笔记本电脑上,但它不工作的Android,因为这个错误。我认为它的所有关于gspread,但哪里是问题,为什么仍然给这个错误?
TL;DR: 添加 google-auth
到您现有的 requirements
你的 buildozer.spec
说来话长。
是的,buildozerp4a默认不能自动解决包的依赖关系。
所以我们要调试的方法是找到自己缺少的包,从stacktrace中检查这部分。
06-02 15:25:27.121 25609 25949 I python : File
"/home/ademberkaksoy/sheet/.buildozer/android/platform/build-armeabi-v7a/build/python-
installs/myapp/gspread/auth.py", line 12, in <module>
06-02 15:25:27.121 25609 25949 I python : ModuleNotFoundError: No module named 'google'
然后看看 gspread
包装和 auth
模块到底想导入什么。从源码中查看。https:/github.comurnashgspreadblobv3.6.0gspreadauth.py#L12。
from google.oauth2.credentials import Credentials
所以,现在我们需要看看在哪个包上的 Credentials
类正在被定义。有多种方法可以找到它,但由于我们知道它一定是一个依赖关系,我们检查了 setup.py
的同一个包。https:/github.comurnashgspreadblobv3.6.0setup.py#L46-L50。
install_requires=[
'requests>=2.2.1',
'google-auth>=1.12.0',
'google-auth-oauthlib>=0.4.1'
],
在这里,我们看到有3个依赖关系,可以从中寻找。然后我们可以进一步搜索,看看是否在其中一个类中定义了该类。但实际上无论如何我们都会需要一些依赖关系。所以我们可以简单地将它们添加到 buildozer.spec
然后 buildozer android clean
和 buildozer android debug
.应该就是这样了。
但如果我们仍然好奇,这里是它的真正定义。https:/github.comgoogleapisgoogle-auth-library-pythonblobv1.16.0googleoauth2credentials.py#L50。 然后检查该项目README,我们看到它确实来自于 google-auth
包。