我正在制作一个接收一些参数并使用这些参数来操作 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
上的导入(没有显示整个程序,因为它来 self 的工作,我不能,抱歉)
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]
我仅使用参数并构建 .exe 进行了测试,并且它有效,因此问题可能出在模块或我的环境上。
有什么想法吗?
最佳答案
编辑:尝试修改您的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 中找到有关如何将 requests
与 cx_Freeze
结合使用的更多信息.
您可能还需要将任何必要的文件(许可证文件、证书……?)添加到 include_files
列表中。
就cx_Freeze
报告的Missing module
列表而言,这不一定是问题。
关于python - 模块未找到错误 : No module named 'google' on python 3. 6.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54188821/