Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Updated November 30, 2026 · Written and reviewed under our editorial policy
To run a Python script, open a terminal in the script's folder and type python3 script.py on Mac or Linux, or py script.py on Windows, then press Enter. Python runs the file top to bottom and prints any output in the terminal. In VS Code, open the file and click the Run Python File button.
Source: Python documentation, "Command line and environment" and "Using Python on Windows"; Visual Studio Code documentation, "Run Python code", checked 2026-11-28.
On Windows, run a Python script with the py launcher, which the python.org installer sets up for you. Open Command Prompt or PowerShell, go to the folder that holds the script and run it:
cd C:\Users\you\projects
py script.pyThe py script.py command works the same way in Command Prompt, PowerShell and Windows Terminal. The one PowerShell difference shows up when you type a file name on its own: PowerShell only runs a file from the current folder when you put .\ in front of it. Not sure which Python py starts? check your Python version with py --version.
Double-clicking a .py file in File Explorer also runs it, but the console window closes as soon as the script ends, so you rarely see the output or the error message. Run scripts from a terminal while you're writing and testing them.
Writing Python test scripts? Run them across 3,000+ browsers on TestMu AI's Selenium grid instead of your laptop. You can also test on 3,000+ browsers by hand with TestMu AI (formerly LambdaTest).

On Mac and Linux, run a Python script with the python3 command. Open Terminal, move into the script's folder and run it:
cd ~/projects
python3 script.pyUse python3 rather than python. Current macOS versions have no python command at all, and on many Linux distributions python is missing, or on older systems points to Python 2. On a Mac without developer tools, typing python3 opens a prompt to install Apple's command line developer tools. If python3 isn't found, set up Python on macOS.
Terminal.app is enough, though several alternative terminal apps for Mac add split panes and search. If the script lives in a Git project, clone the repository first and run it from the project folder.
VS Code runs a Python script with one click once Microsoft's Python extension is installed.
Source: Visual Studio Code documentation, "Run Python code", checked 2026-11-28.
If VS Code runs the wrong Python, open the Command Palette (Ctrl+Shift+P, or Cmd+Shift+P on Mac), run Python: Select Interpreter and pick the one you want. The selected interpreter shows in the status bar. You can also skip the button and type python3 script.py in VS Code's built-in terminal (View > Terminal).
VS Code is one of several Python editors we compared. To tidy indentation and spacing before a run, format messy Python code in your browser. When a script runs but gives the wrong result, step through it line by line; see Python debuggers compared.
Arguments for a Python script go after the file name, separated by spaces: python3 script.py input.csv (Windows: py script.py input.csv). Python stores them in the sys.argv list. sys.argv[0] is the script's name, and sys.argv[1] onward are the arguments, always as strings.
import sys
print("Script:", sys.argv[0])
print("Arguments:", sys.argv[1:])Running python3 script.py input.csv out.txt prints Script: script.py and Arguments: ['input.csv', 'out.txt']. Put quotes around an argument that contains spaces. For named options such as --verbose and an automatic --help message, use the argparse module from the standard library.
Making a Python script executable on Mac and Linux takes two changes: a shebang line at the top and the execute permission. After that you can run it by its name, without typing python3.
The #!/usr/bin/env python3 line tells the system to use the first python3 on your PATH, so it works whether Python came from python.org, Homebrew or your Linux distribution. Windows doesn't need any of this: py script.py works without it, and the py launcher reads a shebang line, if there is one, to choose which Python to use.
The -m option runs a Python module by its name instead of a file path. Python finds the module on its import path and runs it as a script. For example, this starts a small web server that shares the current folder:
python3 -m http.serverOpen http://localhost:8000 in a browser to see the folder, and press Ctrl+C in the terminal to stop the server. On Windows, type py -m http.server. Many tools run the same way: python3 -m venv .venv creates a virtual environment, and python3 -m pip install requests uses the pip that belongs to that exact Python. If Python says there's no module named pip, install pip first.
On Mac and Linux, cron runs a Python script on a schedule. Run crontab -e and add a line like the one below, which runs report.py at 9:00 every day. Use full paths for both Python and the script, because cron starts with a minimal environment and doesn't read your shell settings. Find Python's full path with which python3.
0 9 * * * /usr/bin/python3 /home/you/scripts/report.pyOn Windows, Task Scheduler does the same job. Open it from the Start menu, click Create Basic Task, give the task a name and pick a trigger such as Daily. For the action, choose Start a program, put the full path to python.exe in Program/script, the script's full path in Add arguments and the script's folder in Start in. To find python.exe, run py -c "import sys; print(sys.executable)".
A scheduled script can also run a test suite every night. To automate browser tests with Python, set up Selenium first.
The "'python' is not recognized as an internal or external command" error on Windows means Windows can't find python.exe on your PATH. Before you debug PATH, check which Python version is installed. Then pick one of these fixes:
"python3: can't open file ... [Errno 2] No such file or directory" means Python started but can't find the script. You're in a different folder, or the file name is misspelled. List the folder with ls (Mac and Linux) or dir (Windows), cd into the right one, or pass the script's full path.
On Mac and Linux, "/usr/bin/env: 'python3\r': No such file or directory" when you run ./script.py means the file was saved with Windows line endings. Switch it to LF line endings in your editor (in VS Code, click CRLF in the status bar and choose LF) and save it again.
If the script fails with "No module named", install pip for that Python and then the package.
Open a terminal in the script's folder and run python3 script.py on Mac or Linux, or py script.py on Windows. Python runs the file and prints its output in the same window.
Python isn't on your PATH, so Windows can't find python.exe. Run the script with the py launcher instead (py script.py), or add Python to PATH: accept the Python install manager's PATH prompt, or re-run the traditional python.org installer and tick Add python.exe to PATH.
Install the Python extension, open the file and click the Run Python File button in the top-right corner of the editor. The output appears in VS Code's terminal panel.
Add the arguments after the file name, for example python3 script.py input.csv. Inside the script, read them from sys.argv: sys.argv[1] is the first argument.
For a quick test, yes: paste the code into an online Python interpreter in your browser. For real projects, install Python so your scripts can read local files and use the packages you need.
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.

TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance