How do I get my python matplotlib object to show in GCP terminal?

Viewed 44

I have a python script running in a GCP terminal environment. When I use plt.show(), nothing pops up for me to view whatever plot I'm trying to see.

How do I get the matplotlib.pyplot or seaborn plots to show in the GCP terminal?

1 Answers

The Cloud CLI is not capable of displaying images or graphics. Because this is impossible using the CLI, you can create a VM to run Python with the matplotlib.pyplot or seaborn. The other option is to save the image file locally and then upload it to GCP.

Once you have created the VM (if you decide to use the VM) with the desired OS and processor, use the following command to download Linux 64-bit:

curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-402.0.0-linux-x86_64.tar.gz

Extract the contents of the file to any location on your file system (preferably your Home directory):

tar -xf google-cloud-cli-402.0.0-linux-x86.tar.gz

Then, run the installation script from the root of the folder you extracted to using the following command:

./google-cloud-sdk/install.sh

To initialize the gcloud CLI, run gcloud init:

./google-cloud-sdk/bin/gcloud init

A more in-depth guide for installing Python in the VM can be found in the following link 1, Link 2. Python can be installed in different OS, and the documentation has guides for most OS.

Related