在Kivy期间没有模块化的命名谷歌与Buildozer的apk



Her my main.py

# -*- 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添加到您现有的buildozer.specrequirements

说来话长:

是的,默认情况下,buildozer/p4a 还不能自动解析包依赖项。

因此,我们想要调试的方法是找到缺少哪个包。 从堆栈跟踪中检查此部分:

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.com/burnash/gspread/blob/v3.6.0/gspread/auth.py#L12

from google.oauth2.credentials import Credentials

所以现在我们需要看看Credentials类是在哪个包上定义的。 有多种方法可以找到它,但由于我们知道它一定是一个依赖项,因此我们检查同一包的setup.py。 https://github.com/burnash/gspread/blob/v3.6.0/setup.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 cleanbuildozer android debug。 应该就是这样了。

但是,如果我们好奇它仍然在这里真正定义 https://github.com/googleapis/google-auth-library-python/blob/v1.16.0/google/oauth2/credentials.py#L50 然后检查该项目自述文件,我们看到它确实来自google-auth包。

相关内容

  • 没有找到相关文章

最新更新