【问题标题】:ModuleNotFoundError: No module named 'google' on python 3.6.7ModuleNotFoundError:python 3.6.7 上没有名为“google”的模块
【发布时间】:2019-01-14 20:37:33
【问题描述】:

我正在制作一个脚本,它接收一些参数并使用这些参数来操作 Firebase 实时数据库。

当我通过键入mpython myScript.py arg1 arg2 ... 在 cmd(我在 Windows 10 计算机上)上运行脚本时,它工作正常。但是当我使用 cx_Freeze 构建我的 .exe 时,它​​说缺少模块

Missing modules:
? Cookie imported from requests.compat
? OpenSSL.SSL imported from urllib3.contrib.pyopenssl
? OpenSSL.crypto imported from urllib3.contrib.pyopenssl
? StringIO imported from requests.compat, six, urllib3.packages.six
....
? urllib3.packages.six.moves.urllib.parse imported from 
urllib3.poolmanager, urllib3.request
? urlparse imported from requests.compat
? vms_lib imported from platform
This is not necessarily a problem - the modules may not be needed on this 
platform.

它也显示

Traceback (most recent call last):
  File "C:\Users\engenharia1\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\Users\engenharia1\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "Api2.py", line 8, in <module>
  File "C:\Users\engenharia1\AppData\Local\Programs\Python\Python36\lib\site-packages\firebase_admin\__init__.py", line 23, in <module>
    from firebase_admin import credentials
  File "C:\Users\engenharia1\AppData\Local\Programs\Python\Python36\lib\site-packages\firebase_admin\credentials.py", line 20, in <module>
    import google.auth
ModuleNotFoundError: No module named 'google'

我的setup.py

import sys
from cx_Freeze import setup, Executable

setup ( 
    name = "pyFirebase",
    version = "1.1",
    executables = [Executable("pyFirebase.py")]
)

我在pyFirebase.py 上的导入(没有显示整个程序,因为这是我的工作,我不能,抱歉)

import sys
import os

import datetime

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db

from random import randint

以及我处理参数的方式

if(len(sys.argv) == 5):
    var1 = args[1]

我只使用 args 并构建了 .exe 进行了测试,它工作正常,所以问题可能出在模块或我的环境中。

有什么想法吗?

【问题讨论】:

    标签: python firebase cx-freeze


    【解决方案1】:

    编辑:尝试修改您的setup.py,如下所示:

    import sys
    from cx_Freeze import setup, Executable
    
    include_files = []
    packages = ['google']
    build_exe_options = {'include_files': include_files,
                         'packages': packages}
    
    setup ( 
        name = "pyFirebase",
        version = "1.1",
        options = {'build_exe': build_exe_options},
        executables = [Executable("pyFirebase.py")]
    )
    

    google 使用requests,您将在Requests library: missing SSL handshake certificates file after cx_Freeze 中找到有关如何使用requestscx_Freeze 的更多信息。

    您可能还需要将任何必要的文件(许可证文件、证书……?)添加到include_files 列表中。

    cx_Freeze上报的Missing modules列表而言,这不一定是问题。

    【讨论】:

    • 我尝试import google,但仍然遇到同样的错误。不一定是问题,但不幸的是,在这种情况下,这是一个问题。尽管执行了 .exe,但没有任何效果。
    • @HenriqueZanferrari 您是否收到相同的错误或 .exe 已执行?这个说法我不清楚。无论如何,我已经用一个可能更好的建议编辑了我的答案,并添加了更多信息。
    【解决方案2】:

    我通过将 python 版本更改为 3.7.2 并使用 pyinstaller(我之前尝试过但也没有用)而不是 cx_freeze 解决了这个问题。

    不知道为什么,但它现在可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-06
      • 2019-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      • 1970-01-01
      • 2022-07-21
      相关资源
      最近更新 更多