我正在尝试连接Firebase身份验证。我安装了必需的模块,但无法解决以上错误。
我试图为gcloud创建一个钩子目录,但仍然没有解决问题。
import pyrebase
config = {
"apiKey": "AIzaSyA13_Zm0WCy4Rg1gPVZ12kPM4p5ei6b40A",
"authDomain": "timbercal-ecrew1.firebaseapp.com",
"databaseURL": "https://timbercal-ecrew1.firebaseio.com",
"storageBucket": "timbercal-ecrew1.appspot.com"
}
firebase = pyrebase.initialize_app(config)
print("Hi Sam")
这是我遇到的错误:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/samas/PycharmProjects/Testind2/FirebaseAuth.py", line 1, in <module>
import pyrebase
File "C:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\samas\AppData\Local\Programs\Python\Python37-32\lib\pyrebase\__init__.py", line 1, in <module>
from .pyrebase import initialize_app
File "C:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\samas\AppData\Local\Programs\Python\Python37-32\lib\pyrebase\pyrebase.py", line 18, in <module>
from gcloud import storage
File "C:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\samas\AppData\Local\Programs\Python\Python37-32\lib\gcloud\__init__.py", line 19, in <module>
__version__ = get_distribution('gcloud').version
File "C:\Users\samas\AppData\Local\Programs\Python\Python37-32\lib\pkg_resources\__init__.py", line 481, in get_distribution
dist = get_provider(dist)
File "C:\Users\samas\AppData\Local\Programs\Python\Python37-32\lib\pkg_resources\__init__.py", line 357, in get_provider
return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
File "C:\Users\samas\AppData\Local\Programs\Python\Python37-32\lib\pkg_resources\__init__.py", line 900, in require
needed = self.resolve(parse_requirements(requirements))
File "C:\Users\samas\AppData\Local\Programs\Python\Python37-32\lib\pkg_resources\__init__.py", line 786, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'gcloud' distribution was not found and is required by the application
答案 0 :(得分:0)
我遇到了同样的错误,我使用pyinstaller提供的钩子机制修复了该错误,您可以尝试执行此操作。在同一工作目录内创建一个名为hooks的文件夹。在hooks文件夹中,创建一个名为hooks-gcloud.py
的文件。hooks-gcloud.py
的内容from PyInstaller.utils.hooks import copy_metadata, collect_data_files
datas = copy_metadata('gcloud')
datas += collect_data_files('requests')
然后尝试运行pyinstaller命令。
pyinstaller -F --noconsole --hidden-import="pyrebase" --additional-hooks-dir ./hooks/ --clean filetocompile.py
您可以添加--clean来删除缓存。