ModuleNotFoundError:在Python 3.6.7上没有名为“ google”的模块

时间:2019-01-14 20:37:34

标签: python firebase cx-freeze

我正在制作一个脚本,该脚本接收一些参数,并使用这些参数来操纵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

我对args的处理方式

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

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

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

我通过将python版本更改为3.7.2并使用pyinstaller(我曾尝试过但也没有起作用)而不是cx_freeze来解决了该问题。

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

答案 1 :(得分:0)

编辑:尝试如下修改您的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列表中添加任何必要的文件(许可证文件,证书等)。

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