Caveat
This fits in the category of “What it ended up being for me, and it may help someone else” and not “I’m an expert on all gcloud
errors, and this is always the solution,” so please resist the urge to comment with “This didn’t solve it for me. What’s the solution to my problem?” The answer will probably be “I don’t know what the solution to your problem is, then.”
Problem
I was trying to deploy a Google Cloud Function using gcloud functions deploy
, and I kept getting this error:
WARNING: Requirement './SUBDIR/NAMEOFCUSTOMPYTHONMODULE.whl' looks like a filename, but the file does not exist
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/workspace/SUBDIR/NAMEOFCUSTOMPYTHONMODULE.whl'; Error ID: c84b3231
That file definitely existed. I knew that .whl
was there, and I’d deployed custom Python modules this way many times for other Cloud Functions.
So I tried uploading a .zip
of the function instead of using gcloud functions deploy
, and that failed also, but it gave me a slightly more useful message:
Build failed: missing main.py and GOOGLE_FUNCTION_SOURCE not specified. Either create the function in main.py or specify GOOGLE_FUNCTION_SOURCE to point to the file that contains the function
Solution
That was also initially baffling, because I definitely had a main.py
file in the project. So I did some more searching, and I finally found the solution on StackOverflow.
All I had to do was delete a line from the .gcloudignore
file:
#!include:.gitignore
I noticed that line wasn’t in the .gcloudignore
file for my other Cloud Functions, and deleting that did, in fact, solve the failure to be able to deploy the Cloud Function.
So, I don’t know if that’ll solve everybody’s problems, but it solved mine, and maybe it’ll solve at least one other person’s problems.
Semi-related other Cloud Function stuff
- You may have to specify in the requirements file a specific
protobuf
version to get your (Python) Cloud Function to work. - If your logging statements aren’t appearing in Logs Explorer, you may want to use Python 3.7 instead of a later version.
Leave a Reply