问题
I'm making a script that receives some args and use these args to manipulate a Firebase Realtime Database.
When I run the script on cmd (I'm on a Windows 10 computer) by typing mpython myScript.py arg1 arg2 ...
it works fine. But when I use cx_Freeze to build my .exe it says that there are modules missing
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.
And it also shows
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'
My setup.py
import sys
from cx_Freeze import setup, Executable
setup (
name = "pyFirebase",
version = "1.1",
executables = [Executable("pyFirebase.py")]
)
My imports on pyFirebase.py
(not showing the whole program because it's from my job, I can't, sorry)
import sys
import os
import datetime
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
from random import randint
And my way of handling with the args
if(len(sys.argv) == 5):
var1 = args[1]
I did a test using just the args and building the .exe and it worked, so probably the issue is with the modules or with my environment.
Any ideas?
回答1:
EDIT: try to modify your setup.py
as follows:
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
uses requests
, you'll find additional information on how to use requests
with cx_Freeze
in Requests library: missing SSL handshake certificates file after cx_Freeze.
You might further need to add any necessary file (license file, certificate, ...?) to the include_files
list.
As far as the Missing modules
list reported by cx_Freeze
is concerned, this is not necessarily a problem.
回答2:
I solved it by changing the python version to 3.7.2 and using pyinstaller (wich I've tried before and also didn't worked) instead of cx_freeze.
Don't know why, but its working now.
来源:https://stackoverflow.com/questions/54188821/modulenotfounderror-no-module-named-google-on-python-3-6-7