Hello everyone,
I’m deploying a Python Cloud Function on Google Cloud Run (via Cloud Functions Gen 2) that processes .xlsx Excel files. The function uses pandas.read_excel() with openpyxl as the engine.
I’m working on a Google Cloud Function (Python 3.11-tried on 3.10 also same problem) that downloads .xlsx reports from Google Drive using the Google Drive API. It uses pandas.read_excel() to parse the Excel content:
pythonCopyEditfh = io.BytesIO()
request = drive_service.files().get_media(fileId=file_id)
downloader = MediaIoBaseDownload(fh, request)
while not done:
_, done = downloader.next_chunk()
fh.seek(0)
df = pd.read_excel(fh, engine="openpyxl")
Even though I have added openpyxl to my requirements.txt and verified that the dependency is correctly installed (alongside a test library), the deployment fails with the following runtime error:
vbnet
ImportError: No module named expat; use SimpleXMLTreeBuilder instead
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
The full traceback shows the error arises when openpyxl attempts to parse XML using Python’s built-in xml.etree.ElementTree, which internally depends on the missing libexpat module in the Cloud Run environment. As a result, the container fails the TCP probe and the revision never becomes ready.
Steps I’ve taken:
-
Verified requirements.txt is correctly processed (added test libraries and confirmed output).
-
Confirmed the error persists even after switching Python versions (3.10 → 3.11).
-
Tried installing additional parsing libraries (lxml, etc.) — no effect.
-
openpyxl works perfectly in my local environment but fails in the Cloud Function container.
Questions:
- How can I read excel file on my cloud run?
Any guidance or official response would be greatly appreciated.
Thank you,
Hamza