“google-cloud-firestore”分发版未添加到 PyInstaller 构建中

Ili*_*rov 2 python pyinstaller firebase

当我尝试为我的 python 脚本构建一个可执行文件时,它给了我:

pkg_resources.DistributionNotFound: The 'google-cloud-firestore' distribution was not found and is required by the application
Run Code Online (Sandbox Code Playgroud)

我创建了以下钩子:'hook-google-cloud-firestore.py' 和 'hook-google.cloud.py',但它似乎也没有帮助。任何想法如何解决这个问题?

bez*_*zos 8

这两天,我用三个步骤找到了解决方案

第一的

hook-google.cloud添加此代码。

datas += copy_metadata('google-cloud-firestore')
Run Code Online (Sandbox Code Playgroud)

hook-google.cloud.py .. 的根

C:\Users\ASPIREone\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\PyInstaller\hooks
Run Code Online (Sandbox Code Playgroud)

第二

制作

hook-google-cloud-firestore.py
Run Code Online (Sandbox Code Playgroud)

在根:

C:\Users\ASPIREone\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\PyInstaller\hooks
Run Code Online (Sandbox Code Playgroud)

并添加此代码

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')
Run Code Online (Sandbox Code Playgroud)

不要忘记删除__pycache__主项目中的文件夹我的主项目是根目录 C:\Users\ASPIREone\PycharmProjects\amazon\parking-go

第三

在以下根目录中删除您的应用程序(例如:main.exe):

C:\Users\ASPIREone\AppData\Local\Programs\Python\Python37-32\Scripts\dist
Run Code Online (Sandbox Code Playgroud)

转到命令行

不使用pyinstaller.exe --onefile main.py但使用

pyinstaller.exe --onefile --clean main.py

因为我的主要项目在根文件夹中所以我在命令行中写:

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
Run Code Online (Sandbox Code Playgroud)

它通过这一步解决了:

将文件复制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
Run Code Online (Sandbox Code Playgroud)

制作hook-grpc.py并放置此代码

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('grpc')
Run Code Online (Sandbox Code Playgroud)

转到命令行

pyinstaller.exe --onefile --clean yourmainfile.py
Run Code Online (Sandbox Code Playgroud)

它应该工作!