Execution guideUpdated October 2026•6 min read

How to run a .py file online and in Windows terminal

A .py file contains plain-text Python source code. You can execute this file directly inside a browser through WebAssembly file mounting, or on a Windows workstation using PowerShell and the Python launcher.

Have a .py file to run?
Upload and execute your file in the browser runner without installing Python.
Upload and run .py file

Running a .py file online through browser file upload

Online runners allow you to test scripts without configuring operating system paths. When you click the Upload button in the workspace tab strip on python-code-runner.com, the browser uses the HTML5 FileReader API to read the text content of your .py file into browser memory.

The runner writes this text to the Pyodide virtual file system under the root directory as /filename.py. You can upload multiple files such as main.py and data.json into the same virtual file system. When you execute main.py, relative imports locate helper files in the same virtual working directory.

# Example of multi-file relative import in WebAssembly VFS
# File: main.py
import helper
result = helper.calculate_vat(100.0, 0.20)
print(f"Calculated VAT total: {result}") # prints: 120.0

Running a .py file locally on Windows via PowerShell

Windows requires a local CPython interpreter installation. Download the official 64-bit installer for Python 3.12 from python.org. Check the box labeled "Add python.exe to PATH" during installation. This option writes the directory path C:\Users\<username>\AppData\Local\Programs\Python\Python312 into your user PATH environment variable.

Open PowerShell by pressing Windows Key + R, typing powershell, and pressing Enter. Change directory to the folder containing your script using the Set-Location command:

# Navigate to directory and execute
cd C:\Users\kamlesh\Desktop\my-python-project
python script.py

Windows also includes the Python launcher binary named py.exe. When you have multiple Python versions installed, such as Python 3.11 and Python 3.12, py.exe allows you to select the runtime explicitly:

# Targeting specific Python versions with the Windows launcher
py -3.12 script.py
py -3.11 script.py

Creating isolated virtual environments with venv

Installing libraries globally with pip can cause version conflicts across different software projects. The Python standard library provides the venv module to create self-contained directory trees.

Run the following three commands in PowerShell to create and activate a project environment:

# Virtual environment setup on Windows
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install requests==2.31.0
python main.py

If PowerShell blocks the activation script with an execution policy error, run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser to permit locally created scripts.

Resolving common Windows file execution errors

Three errors occur frequently when executing .py files on Windows workstations.

Error 1: "python is not recognized as an internal or external command"

This message means the directory containing python.exe is missing from the system PATH variable. Run the installer again, choose Modify, and select the checkbox for environment variable registration.

Error 2: "No such file or directory"

This error occurs when PowerShell runs in a different folder than the script file. Verify your current directory with the Get-Location command (or pwd) and verify the file presence with Get-ChildItem.

Error 3: Script window closes immediately after execution

Double-clicking a .py file in Windows File Explorer opens a temporary console window that closes as soon as the last line finishes. To inspect output, run the script from an active PowerShell session, or append input("Press Enter to exit...") to the end of your script.

Execute your .py file in the browser

Upload your Python script to python-code-runner.com to test code, inspect variables, and view output without local software configuration.

Open Python Code Runner