How to run a Python script: Get started in 2 minutes

TL;DR: If you’re comfortable with the Terminal and the command line, you can simply save a file as a “.py” file and run the script using “python your_file.py”. Alternatively, if you want to start even simpler, you can simply log in to Fabi.ai and copy/paste the script in a Python cell or ask ChatGPT to run the code for you.

Running a Python script is one of the most fundamental tasks every programmer must learn, but you may also have been given a Python script from a coworker or AI and trying to figure out what to do with it.. Whether you’re a beginner writing your first program or an experienced developer looking for a convenient execution method, knowing different ways to run a Python script can save you time and effort.

This guide will walk you through three different ways to run a Python script:

  1. Using the Command Line (Hardest, but not that hard)
  2. Using ChatGPT (Easier)
  3. Using Fabi.ai (Easiest)

Each method has its own advantages and use cases, and by the end of this guide, you'll know which one is best suited for your needs.

For the visual learners, we have a video that walks you through each example:

1. Running a Python script from the command line (hardest)

The command line (also called the terminal in macOS/Linux or Command Prompt/PowerShell in Windows) is one of the most common and powerful ways to run Python scripts. This method is widely used by developers, especially when working on larger projects, automation scripts, or server-side applications.

Why Use the Command Line?

  • ✅ Fast and efficient once you’re comfortable with it.
  • ✅ Works on any system (Windows, macOS, Linux).
  • ✅ Essential for running Python scripts in production environments.
  • ❌ Requires knowledge of basic command-line navigation.

Step 1: Create a Python script

Before running a Python script, you need to create one.

Open a text editor like Notepad (Windows), TextEdit (Mac), VS Code, or Sublime Text.

Copy and paste the following code:

print("Hello, World!")

Save the file as hello.py.

Make sure the file extension is .py, which tells the system that it’s a Python script.

Step 2: Open the command line

To run the script, search for Terminal or PowerShell and open the program:

  • On Windows: Press Win + R, type cmd, and hit Enter.
  • On macOS: Open Terminal (Finder > Applications > Utilities > Terminal).
  • On Linux: Use the built-in terminal.

Step 3: Navigate to your script’s location

The command line starts in your home directory, so you need to navigate to the folder where your script is saved.

Use these commands:

Check your current directory

pwd  # (macOS/Linux)
echo %cd# (Windows)

Change directory (cd) to your script’s location

cd path/to/your/folder

For example, if your script is in the "Documents" folder:

cd Documents

List files in the directory

ls  # (macOS/Linux)
dir  # (Windows)

Step 4: Run the Python script

Once you’re in the correct directory, type the following command:

python hello.py

You should see the output:

Hello, World!

Installing Python (if needed)

If your system doesn’t recognize the python command, you may need to install Python.

  1. Download Python from python.org.
  2. Install it and make sure to check the box that says "Add Python to PATH" (on Windows).

Verify the installation by running:

python --version

💡 Command line pros: Best for developers, automation, and large-scale projects.
⚠️ Command line cons: Requires setup, typing commands manually, and familiarity with basic shell commands.

2. Running a Python script in ChatGPT (easier but limited)

If you just want to test out a Python script without installing anything, ChatGPT can be a quick way to run simple Python code online.

Why use ChatGPT?

  • ✅ No installation needed – Just type and run code instantly.
  • ✅ Great for quick testing of small scripts.
  • ❌ Limited functionality – Cannot handle complex scripts, external file interactions, or custom libraries.

Step 1: Ask ChatGPT to run a script

Simply type:

Run the following Python script:

Then paste your Python code inside triple single quotes ('''):

'''print("Hello, World!")'''
Asking ChatGPT to run a basic Python script

Step 2: Verify the output

ChatGPT will process and execute the script, then return the output.

To ensure that ChatGPT is truly running the script and not just interpreting the text, you can ask it to generate and execute a more complex script:

import matplotlib.pyplot as plt
import numpy as np

# Generate fake data
x = np.arange(10)
y = np.random.randint(1, 100, 10)

# Plot the data
plt.plot(x, y, marker='o')
plt.title("Random Data Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()

If ChatGPT successfully plots the data, it confirms that it can run more than just basic print statements.

ChatGPT allows you to do some basic Python script editing

💡 ChatGPT pros: Quick, easy, and no installation required.
⚠️ ChatGPT cons: Limited capabilities; cannot handle advanced projects.

3. Running a Python script in Fabi.ai (easiest & most powerful)

Fabi.ai is an AI-powered coding platform that allows you to write, execute, and debug Python scripts in your browser—without installing anything!

Why use Fabi.ai?

  • ✅ No setup required – Runs in a web browser.
  • ✅ Auto-debugging – AI detects and fixes errors automatically.
  • ✅ Built-in package management – Automatically installs required libraries.
  • ✅ Best for data analysis & machine learning.

Step 1: Log in to Fabi.ai

  1. Go to Fabi.ai
  2. Sign in using Google or create an account.

Step 2: Write and run your script

Once logged in, you can write Python code directly in Fabi.ai’s editor.

For example, to print "Hello, World!" in Fabi.ai:

print("Hello, World!")

Hit the Run Code button, and Fabi.ai will execute the script instantly.

Running a Python script in Fabi.ai is as simple as copy/pasting your code.

Advanced example in Fabi.ai

If you want to analyze a dataset:

import pandas as pd

# Create a sample DataFrame
data = {
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [25, 30, 35],
    'Salary': [50000, 60000, 70000]
}

df = pd.DataFrame(data)

# Display the DataFrame
print(df)

Fabi.ai will execute the script, display the DataFrame, and even provide AI-powered suggestions for further analysis.

💡 Fabi.ai pros: Beginner-friendly, fast, and AI-assisted debugging.
⚠️ Fabi.ai cons: Best suited for enterprise 

Which method should you use to run a Python script?

  • Use Command Line if you're comfortable with a terminal and need full control over your scripts.. Best for advanced users, building advanced automation and software development.
  • Use ChatGPT if you just want to test small snippets quickly. Great for basic scripts that don’t use any advanced Python packages and don’t need to be productionized.
  • Use Fabi.ai if you want the simplest way to run Python scripts, especially for data analysis and data science. With Fabi.ai, you can also leverage embedded AI to help write scripts and debug Python.

Sign up for free to get started with Fabi.ai in less than 2 minutes!

Related reads

Subscribe to Query & Theory