简体   繁体   中英

How to resolve ImportError when using python pandas read_excel in program deployed to Google Cloud Run

My program reads data from Excel files that are stored in Google Cloud Storage buckets using the pandas read_excel method. The program works fine when run locally, but I am getting this ImportError when I try to run the program after it is deployed to Google Cloud Run: ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.

I have included openpyxl in the requirements.txt and the Cloud Build logs say it is successfully installed when the docker image is built. For reference, here is the content of the Dockerfile I am using to build the image:

# identify base image to use
FROM python:3.9-slim

# create working directory
WORKDIR /app

# copy source code into image
COPY . .

# copy requirements.txt to working directory into the image
# COPY ./requirements.txt ./

# install app dependencies into image
RUN pip install --no-cache-dir -r requirements.txt

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE = True

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED = True

ENV APP_HOME /app

ENV PORT=5000

# Expose port
EXPOSE 5000

# run main.py
# CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "main:app"]
# CMD ["python3", "main.py"]

I am aware of this question , but like I said, I am able to load the data with no issues when running locally, so I don't think the cloud storage file path is the source of the problem. It seems to be an environment issue. Any suggestions?

This issue has been resolved. I did not realize that I needed to manually choose the image build and re-deploy. I thought that if the build was successful, it would automatically deploy with the most recent build. So my subsequent tests did not actually use the updated requirements.txt... Adding openpyxl to the requirements.txt fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM