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',但它似乎也没有帮助。任何想法如何解决这个问题?
这两天,我用三个步骤找到了解决方案
在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)
它应该工作!
| 归档时间: |
|
| 查看次数: |
1082 次 |
| 最近记录: |