From around the end of 2019, I was working on developing Python on GCP's Cloud Shell and deploying it to Cloud Function. After developing for a while and leaving it for a few months, a new development project has recently occurred, so when I thought about deploying and testing it, I started to throw out various errors at the time of deployment. I tried to deal with it while looking at the error, but it didn't work, and when I finally reset the environment, it worked, so I will summarize it.
Updating and switching versions of Python and pip was the biggest stalemate.
After exporting the installed packages with pip freeze> requirements.txt
, let's download all the files on Cloud Sell Editor.
The file will be tarred down. You don't need to unpack it because you will raise it as tar later.
** Disable or reset Cloud Shell ** https://cloud.google.com/shell/docs/resetting-cloud-shell?hl=ja
According to
sudo rm -rf $HOME
It seems that you can go by restarting Shell after resetting.
This Qiita was helpful, thank you to the person who wrote it.
** How to update the python version of Cloud Shell on GCP ** https://qiita.com/greenteabiscuit/items/cbecdf4f84f0b73ff96e
I'm running on python 3.7.9.
If you pip it as it is, it will be displayed as python v2, so be careful. If left unattended, an error was thrown when deploying Cloud Function, so it seems better to use pip3 here as well. Switch to the command reference on the following site https://www.it-swarm-ja.tech/ja/pip/pip3%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%82%92pip%E3%81%AB%E5%A4%89%E6%9B%B4%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%82%88%E3%81%84%E3%81%A7%E3%81%99%E3%81%8B%EF%BC%9F/831723093/
alias pip=pip3
I can go.
After that, use pip install -U pip
to update to the latest version.
I also had to update gcloud. Officially this is the procedure:
gcloud components update https://cloud.google.com/sdk/gcloud/reference/components/update
gcloud components update
Is the command.
However, on Shell, it cannot be updated with this,
sudo apt-get update && sudo apt-get --only-upgrade install google-cloud-sdk-app-engine-python-extras google-cloud-sdk-kpt google-cloud-sdk-minikube google-cloud-sdk-app-engine-java google-cloud-sdk-datalab google-cloud-sdk-kind google-cloud-sdk-app-engine-grpc google-cloud-sdk-firestore-emulator google-cloud-sdk-bigtable-emulator google-cloud-sdk-skaffold kubectl google-cloud-sdk-cbt google-cloud-sdk-pubsub-emulator google-cloud-sdk-anthos-auth google-cloud-sdk google-cloud-sdk-datastore-emulator google-cloud-sdk-app-engine-python google-cloud-sdk-spanner-emulator google-cloud-sdk-cloud-build-local google-cloud-sdk-app-engine-go
You will be asked to execute a very long command. When I ran it, it was updated properly.
Let's upload the tar that was downloaded in 1. You can go to D & D or right-click where there is nothing in the file list → Upload Files. After uploading, decompress it with the tar command. I referred to this Qiita for how to do it:
** How to compress and decompress [Linux] files ** https://qiita.com/supersaiakujin/items/c6b54e9add21d375161f
tar -xvf xxxx.tar
Command above
Now let's reinstall the pip package. I referred to the following site.
** Bulk installation of packages using requirements.txt with Python and pip ** https://note.nkmk.me/python-pip-install-requirements/
pip install -r requirements.txt
Occasionally, I get an error like "This package cannot be installed without another package", but in that case, if you specify the package name and install it, it will be quite good. I'm just using the bigquery api, but I had to install the related packages below:
pip install google-cloud-bigquery
After that, let's crush the bugs ~~ infinitely by doing gcloud functions deploy
~~.
Perhaps you don't have to worry about changing the version with the blue bar at the bottom of the Editor screen.
Recommended Posts