当我试图为我的python脚本构建一个可执行文件时,它给了我:
pkg_resources.DistributionNotFound: The 'google-cloud-firestore' distribution was not found and is required by the application我创建了以下钩子:“hook-google-cloud-firestore.py”和“hook-google.cloud.py”,但似乎也没有帮助。有什么办法解决这个问题吗?
发布于 2019-05-28 00:50:20
两天来,我通过三个步骤找到了解决方案
第一
在hook-google.cloud中添加以下代码。
datas += copy_metadata('google-cloud-firestore')hook-google.cloud.py的根..
C:\Users\ASPIREone\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\PyInstaller\hooks第二
制作
hook-google-cloud-firestore.py在根目录中:
C:\Users\ASPIREone\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\PyInstaller\hooks并添加以下代码
from PyInstaller.utils.hooks import copy_metadata, get_package_dir
datas += copy_metadata('google-cloud-firestore')
datas += copy_metadata('google_cloud_firestore') #altlll
hiddenimports += ['google-cloud-firestore_v1']
#pythonhosted.org/pyinstaller/hooks.html#understanding-pyinstaller-hooks
#get_package_dir returns tuple (where pkg stored, abs path to pkg)
pkg_dir = 'C:/Users/ASPIREone/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/google/cloud/firestore_v1'
datas += (pkg_dir, 'google-cloud-firestore')别忘了删除主项目中的__pycache__文件夹我的主项目是C:\Users\ASPIREone\PycharmProjects\amazon\parking-go的根目录
第三
删除根目录下的应用程序(示例: main.exe):
C:\Users\ASPIREone\AppData\Local\Programs\Python\Python37-32\Scripts\dist转到命令行
不要使用pyinstaller.exe --onefile main.py,而是使用
pyinstaller.exe --onefile --clean main.py
因为m主项目在根文件夹中,所以我在命令行中写道:
pyinstaller.exe --onefile --clean C:\Users\ASPIREone\PycharmProjects\amazon\parking-go\main.py
你必须先把它清理干净再重建。
它应该是有效的!
.
如果您应用程序在检索数据或写入firestore时出现错误,如下所示:
Exception ignored in: 'grpc._cython.cygrpc.ssl_roots_override_callback'
E0527 07:10:01.571000000 3672 src/core/lib/security/security_connector/ssl_util
s.cc:449] assertion failed: pem_root_certs != nullptr它是通过以下步骤解决的:
将文件roots.pm复制到主项目或where you run your app中
roots.pm的目录是
C:\Users\ASPIREone\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\grpc\_cython\_credentials\roots.pm生成hook-grpc.py并将以下代码放入
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('grpc')转到命令行
pyinstaller.exe --onefile --clean yourmainfile.py它应该是有效的!
发布于 2020-09-25 14:48:43
最近我找到了一个解决方案,希望这也能解决你的问题。
创建两个钩子文件:
在hook-google.cloud.firestore.py中,编写以下代码并将其保存在某个位置:
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('google-cloud-firestore')在hook-grpc.py中,编写以下代码并将其保存在相同的位置:
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files ( 'grpc' )现在将两个文件复制粘贴到:
C:\Users\Paul\AppData\Local\Programs\Python\Python38\Lib\site-packages\PyInstaller\hooks
如果您仍然遇到此问题,请使用setuptools版本45.0.0,然后运行pyinstaller并通过以下方式创建您的exe文件:
pyinstaller --清理--一个文件yourfilename.py
发布于 2020-10-26 17:48:47
如果在PyInstaller包中找不到hooks-google.cloud.py,可以尝试在以下位置找到它:
C:\Users\<USER>\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks或者,如果您使用的是虚拟环境,则可以使用_pyinstaller_hooks_contrib\hooks来构建exe文件,而不是使用它。
如果错误仍然存在,您可以查看构建日志来定位构建hook-google.cloud.py的位置。
我希望这对将来的人有帮助,因为它对我很有效。
https://stackoverflow.com/questions/55848884
复制相似问题