Situation
I have an existing Python app in Google Colab that calls the Twitter API and sends the response to Cloud Storage.
I’m trying to automate the Twitter API call in GCP, and am wondering how I install the requests
library for the API call, and install os
for authentication.
I tried doing the following library installs in a Cloud Function:
import requests
import os
Result
That produced a resulting error message:
Deployment failure: Function failed on loading user code.
Do I need to install those libraries in a Cloud Function? I’m trying to understand this within the context of my Colab python app, but am not clear if the library installs are necessary.
Thank you for any input.
2
Answers
when you create your cloud function source code , there are two files.
Add packages in requirements.txt as below
#Function dependencies, for example:
requests==2.20.0
creating a new python environment for your project might help and would be a good start for any project
it is easy to create.
if you are using google colab, add "!" before these commands, they should work fine.