2
1

More than 5 years have passed since last update.

PyinstallerでFirestoreを使ったPythonスクリプトをEXE化する際のTips

Posted at

PythonでFirestoreを使うスクリプトをWindowsのローカルで実行するように配布する必要があったので、Pyinstallerを利用しました。
少しハマったポイントがありいろいろと調べたのですが、日本語の情報が少なかったので残しておきます。

そもそも、PythonでFirestoreを使うのであればCloud Functionsを使うべきだと思いますが、事情がありどうしてもローカルで実行する必要がありました、、、

環境

  • Windows10
  • Python 3.6.8
  • Anaconda 4.5.12
  • Pyinstaller 3.4

Pyinstaller

Pyinstallerのインストール〜実行までは以下の記事を参考にしました。

Anaconda環境で作成したPythonプログラムをexe化した話。
Pyinstaller でリソースを含めたexeを作成する

ハマったポイントと解決策

EXE実行時エラー:Firestoreのライブラリが見つからない

【解決策】hook-google.cloud.pyにfirestoreライブラリを追記する
Python環境のLib\site-packages\PyInstaller\hooksディレクトリにある、hook-google.cloud.pyの末尾に以下記述を追加しました。

hook-google.cloud.py
datas += copy_metadata('google-cloud-firestore')

EXE実行時エラー:「Exception ignored in: 'grpc._cython.cygrpc.ssl_roots_override_callback'」

【解決策】 specファイルにroots.pemの情報を記載する
このときファイルパスをフルパスで指定する必要がありました。

xxxxx.spec
a = Analysis(...
             datas=[
               ('\\path\\to\\dir\\roots.pem', 'grpc\\_cython\\_credentials\\'),
             ],
             ...
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1