gcloud distribution was not found and is required by the application - python pyinstaller

Viewed 2100

I have a firebase and the data is stored in there. I am accesing it using the firebase module in python

Here's the code:

from firebase import firebase
firebase = firebase.FirebaseApplication(
    'link to my project in firebase', None)

result = firebase.get('/', None)
print(result)

my o/p:

{'name':'steven}

It works great and its so easy to use. But when i converted it to application using pyinstaller, it shows the following below error.

Traceback (most recent call last):
  File "firebase_connect.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/home/paulsteven/.local/lib/python3.5/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "firebase/__init__.py", line 16, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/home/paulsteven/.local/lib/python3.5/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "gcloud/__init__.py", line 19, in <module>
  File "pkg_resources/__init__.py", line 481, in get_distribution
  File "pkg_resources/__init__.py", line 357, in get_provider
  File "pkg_resources/__init__.py", line 900, in require
  File "pkg_resources/__init__.py", line 786, in resolve
pkg_resources.DistributionNotFound: The 'gcloud' distribution was not found and is required by the application
[14554] Failed to execute script firebase_connect

I tried searching stack overflow but they states that google cloud has changed to gcloud, so change it in PyInstaller hooks in spec file. But in my error, my pyinstaller file is already checking for gcloud and shows that gcloud not found. How to make it work.

3 Answers

Found the answer.. It's a naming issue

In Ubuntu:

cd /home/paulsteven/.local/lib/python3.5/site-packages/PyInstaller/hooks/
vim hook-gcloud.py

Change the content to the following:

from PyInstaller.utils.hooks import copy_metadata

datas = copy_metadata('gcloud')

Now create an executable file - it will work great..

You need additional hooks to use firebase and gcloud while converting to .exe using PyInstaller

Create a python file (*.py) at some directory and name it - hook-gcloud.py and write the following code in it -

from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('gcloud')

Now while giving command for pyinstaller use the option --additional-hooks-dir.

Example - If your newly created hook-gcloud.py is located at C:\Users\xyz\Hooks and say you need to convert example.py to example.exe then your command in command prompt will be -

pyinstaller --additional-hooks-dir C:\Users\xyz\Hooks example.py

And you can always use other options like --onefile along with this.

pkg_resources.DistributionNotFound: The 'gcloud' distribution was not found and is required by the application [21369] Failed to execute script

I solved this problem by copy pasting the missing resource gcloud from Python\Python37\Lib\site-packages to dist folder where my .exe file is saved :)

Hope this solves your problem too.

Related