Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Cloud Function does not load openpyxl

After Cloud Run incorporated Cloud Function, I can no longer read Excel from the Bucket.

I am trying to read an Excel file from a Bucket.

The error is that the openpyxl library is not installed even though it is in the req.txf

Error:
Missing optional dependency 'openpyxl'

I believe that after Cloud Function was absorbed by Cloud Run, this error started.

Google's base image for creating Cloud Function has changed.

0 2 166
2 REPLIES 2

Hi @SrKart,

Welcome to Google Cloud Community!

I can see you having a problem with openpyxl not being present while reading an Excel file from a Google Cloud Storage bucket after moving from Cloud Functions to Cloud Run. This appears to be related to the base images used in the deployment environment and its recent modifications. 

You may fix this by taking these steps:

  1. Check your requirements.txt file - Make sure that openpyxl exists by adding the line on the nginx: openpyxl
  2. Save changes and deploy - Once openpyxl is added and requirements.txt is updated, redeploy the Cloud Run function to make sure all packages are installed.

The dependencies are not always bundled as in previous Cloud Functions superlite runner, they have to be defined within the new requirements.txt parameters so that those dependencies can be added in the build.

For more information regarding deploying functions in Cloud Run you may take a look at the official Google documentation: Building and Deploying Cloud Run Functions and Cloud Functions Release Notes.

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.

Hey Greb, I have added openpyxl on my requirements.txt but I am still getting the error:

requirements.txt:
openpyxl==3.1.2

main.py:

pd.read_excel(fh, engine='openpyxl')

The error:
raise ImportError( ImportError: No module named expat; use SimpleXMLTreeBuilder instead
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.