UPDATE
I've documented my problem and solution in much more detail here »


I had been trying to deploy my script as a Cloud Run Service. I should've tried deploying it as a Cloud Run Job. The difference is that cloud run services require your script to listen for a port. jobs do not.

Confusingly, you cannot deploy a cloud run job directly from Artifact Registry. You have to start from the cloud run dashboard.

Answer from Ben on Stack Overflow
🌐
Google
codelabs.developers.google.com › codelabs › cloud-run-hello-python3
Hello Cloud Run with Python | Google Codelabs
March 20, 2026 - For the list of currently supported regions, see Cloud Run (fully managed) locations. ... gcloud run deploy helloworld-python \ --source .
Discussions

docker - How to run a "hello world" python script with Google Cloud Run - Stack Overflow
Forgive my ignorance.. I'm trying to learn how to schedule python scripts with Google Cloud. After a bit of research, I've seen many people suggest Docker + Google Cloud Run + Cloud Scheduler. I've More on stackoverflow.com
🌐 stackoverflow.com
Automating Python with Google Cloud
This tutorial is great. I really wanted to learn this. More on reddit.com
🌐 r/Python
30
120
March 28, 2024
Running a python script on Google Cloud Compute Engine - Stack Overflow
For a machine learning task at school I wrote my own MLP network. The data set is quite big, and training takes forever. I was alerted to the option of running my script on the Google Cloud Compute More on stackoverflow.com
🌐 stackoverflow.com
google cloud platform - Running basic Python script on GCP - Stack Overflow
I know this is basic but I am really struggling on how to get started and am so so so frustrated. I have developed the basis of my app on my windows pc using juypter notebooks and now want to start More on stackoverflow.com
🌐 stackoverflow.com
🌐
Davidmuraya
davidmuraya.com › blog › python-google-cloud-functions-guide
How to Run Python Scripts in the Cloud with Google Cloud Functions
December 3, 2025 - To run it, you would execute python main.py in your terminal. This approach confirms your logic works and that you are handling environment variables correctly before you deploy. Newer (2nd gen) Cloud Functions are built on top of Cloud Run.
🌐
PyPI
pypi.org › project › google-cloud-run
google-cloud-run · PyPI
python3 -m venv <your-env> source <your-env>/bin/activate pip install google-cloud-run · py -m venv <your-env> .\<your-env>\Scripts\activate pip install google-cloud-run
      » pip install google-cloud-run
    
🌐
Google
docs.cloud.google.com › python › getting started with python on compute engine
Getting started with Python on Compute Engine | Google Cloud Documentation
From Cloud Shell, you can deploy to a single Compute Engine instance virtual machine (VM) which runs your app. You need a way to instruct your instance to download and run your code.
Find elsewhere
🌐
Anderfernandez
anderfernandez.com › en › blog › automate-python-script-google-cloud
How to automate a Python script on Google Cloud - Ander Fernández
In this post I explain step by step how you can automate a Python script in Google Cloud with Cloud Functions, Cloud Scheduler and Pub/Sub.
🌐
C2cglobal
c2cglobal.com › articles › how-to-run-python-on-google-cloud-1356
How to Run Python on Google Cloud
Generally speaking, however, any code deployed in Google Cloud is run by a virtual machine (VM). Kubernetes, Docker, and even Anthos make application modernization possible for large applications. In the case of smaller scripts and deployments, a customizable VM instance is adequate for running Python script on Google Cloud and determining processor size, the amount of RAM, and even the operating system of choice for running applications.
🌐
Reddit
reddit.com › r/python › automating python with google cloud
r/Python on Reddit: Automating Python with Google Cloud
March 28, 2024 -

I just published a tutorial series on how to automate a Python script in Google Cloud using Cloud Functions and/or Cloud Run. Feedback would be great. Thanks!

  • Automating Python with Google Cloud

    • Automating Python with Google Cloud Functions

    • Automating Python with Google Cloud Run

Top answer
1 of 5
39

I finally figured this out so I'll post the same answer on my own post that worked for me here. Using Debian Stretch on my VM. I'm assuming you already uploaded your file(s) to the VM and that you are in the same directory of your script.

  1. Make your script an executable

    chmod +x myscript.py
    
  2. Run the nohup command to execute the script in the background. The & option ensures that the process stays alive after exiting. I've added the shebang line to my python script so there's no need to call python here

    nohup /path/to/script/myscript.py &
    
  3. Logout from the shell if you want

    logout
    

Done! Now your script is up and running. You can login back and make sure that your process is still alive by checking the output of this command:

ps -e | grep myscript.py

If anything went wrong, you can check out the nohup.out file to see the output of your script:

cat nohup.out
2 of 5
9

There is even a simpler approach to to run code in the background in gcp and in every linux terminal: using screen linux

Create a new background terminal window:

screen -S WRITE_A_NAME_OF_YOUR_CHOIC_HERE

now you are in a background window in the terminal. Run your code:

python3 mycode.py

Exit screen with the hotkeys and the job will keep running on the background.

ctrl + A + D

You can close all windows now. If you wanna go back and see what's happening. Log again in your terminal. And tap the following.

screen -ls 

This one will give you the list of the created "windows". Now find yours and tap

screen -r WRITE_NAME_OF_YOUR_WINDOW

And there you have it :D You can find more commands here

🌐
DEV Community
dev.to › njoguu › running-a-python-script-on-google-cloud-in-2023-a-step-by-step-guide-272k
Running a Python Script on Google Cloud in 2023: A Step-by-Step Guide - DEV Community
May 31, 2023 - A Google Cloud Platform account: Sign up for GCP if you don't already have an account. Python installed on your local machine: Ensure you have Python installed, preferably version 3.x. A basic understanding of the command line interface (CLI). A basic understanding of Git. Make sure you have a repository set up that contains the Python scripts you want to run on Google Cloud.
🌐
Medium
001-dharmendra.medium.com › getting-started-with-google-cloud-run-deploying-python-scripts-609838f82a8b
Getting Started with Google Cloud Run: Deploying Python Scripts | by dharmendra mishra | Medium
October 16, 2023 - Google Cloud Run is a fully managed compute platform that automatically scales your Python scripts in containers. It allows developers to run their code in containers, deploy it in a serverless environment, and easily scale applications as needed.
🌐
Google
developers.google.com › google workspace › apps script › python quickstart
Python quickstart | Apps Script | Google for Developers
This quickstart guide helps you create a Python command-line application that interacts with the Google Apps Script API using simplified authentication suitable for testing. To run the quickstart, you need Python 3.10.7 or greater, pip, a Google Cloud project, and a Google account with Google ...
🌐
Reddit
reddit.com › r/googlecloud › how to automate a python script with docker and google cloud run
r/googlecloud on Reddit: How to automate a Python script with Docker and Google Cloud Run
December 15, 2022 -

Link

I recently took on the challenge of automating a Python script, on a schedule with Docker and Google Cloud. While it sounds simple, this was quite tricky for me (a data scientist - not an engineer). I documented my steps in the referenced post for others who may find this useful.

Various posts in this sub helped me get this accomplished. (Particularly this).

Note that Google Cloud Run Services are different than Google Cloud Run Jobs. Services require your app to listen for HTTP requests. Jobs don't. This subtle distinction tripped me up, and I don't think it's talked about enough.

🌐
GeeksforGeeks
geeksforgeeks.org › cloud computing › google-cloud-run-working-with-python
Google Cloud Run - Working with Python - GeeksforGeeks
January 13, 2021 - This is where you set your Python runtime. The COPY command adds files from your Docker client's current directory as below: ... The RUN command installs Flask, gunicorn, and currency converter dependencies for the service. ... And finally, CMD is a command to start the application inside the container and bind it to a port. ... The app: app at the end means import our app from the app.py file. One of the advantages of Cloud Run is that you can run any Python version you want as long as there is a base Docker image available for it.