【问题标题】:No moduled named google during Kivy to apk with BuildozerKivy 期间没有名为 google 的模块使用 Buildozer 进行 apk
【发布时间】:2020-06-02 12:55:09
【问题描述】:

她是我的 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 有关,但问题出在哪里,为什么仍然会出现此错误?

【问题讨论】:

  • 您是否安装了 GSpread 工作所需的库?检查您的 gspread 安装,并检查您是否也安装了 google-api-python-client。运行pip install google-api-python-client
  • 我必须这样做吗?因为它的构建器错误。它在电脑上工作

标签: android google-sheets kivy apk buildozer


【解决方案1】:

TL;DR:将google-auth 添加到您现有的requirementsbuildozer.spec

长篇大论:

是的 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.pyhttps://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 包。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 2021-02-03
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多