2

我正在尝试连接 firebase 身份验证。我安装了所需的模块,但上述错误我无法解决。

我试图为 gcloud 创建一个 hooks 目录,但仍然没有解决问题。

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
4

1 回答 1

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 以删除缓存。

看看这个问题

于 2020-06-23T18:41:14.633 回答