Search code examples
pythonartificial-intelligencepyinstaller

PyInstaller-Generated .exe closes Immediately When Running Google Palm-2 program


I wrote a short example of a Python program that sends a prompt to the Google Palm-2 model and receives a reply from the model. My program runs correctly when I run it in the command console with the ".py" extension. However, after I created an ".exe" file using Pyinstaller, and ran the ".exe" file, the command window closed immediately without running the program. Has anyone else experienced the same problem? I spend hours looking into the Pyinstaller analyzer log and at the run time error message and could not find a solution.

import google.generativeai as palm

# Configure the PaLM API
palm.configure(api_key='my-api-key')
input_text = "What is the capital of France?"
# Get the model's response with the given input text
response = palm.generate_text(
    model='models/text-bison-001',
    prompt=input_text,
)
# Get the corrected text as a string
response = response.result
# Print the reply
print("Result:")
print(response)
print()

Solution

  • I believe this GitHub issue may have information regarding your issue: https://github.com/googleapis/google-cloud-python/issues/5774

    Try adding the following:

    from PyInstaller.utils.hooks import collect_data_files
    datas = collect_data_files('grpc')