How-to · VS Code for Mac

How to run a Python file in VS Code on Mac: steps for macOS beginners

To run a Python file in VS Code on Mac, install Python 3 with Homebrew and add the Python extension. Then select that Python as your interpreter, open your .py file, and click the Run Python File button at the top right of the editor, which prints the output in VS Code's terminal.

Updated Checked against VS Code stable 1.145 on macOS with Python 3 installed through Homebrew15 minEasy

Developer typing Python code on a MacBook while running a file in VS Code
Writing and running a Python file on a Mac · Image by Yng_saad from Pixabay

Quick answer

  • Install VS Code from the .dmg, then run Shell Command: Install 'code' command in PATH from ⇧⌘P.
  • Install Python with brew install python3. The macOS system Python is not supported by Microsoft.
  • Install the Python extension (ms-python.python), then select your interpreter from the status bar or ⇧⌘P.
  • Open your .py file, save with ⌘S, and click Run Python File at the top right of the editor.
  • If a module is missing, install it into the same interpreter with python3 -m pip install package-name.

What you need

  • A Mac with Apple silicon or Intel. VS Code ships builds for both.
  • Visual Studio Code stable. The current stable release is 1.145.
  • Homebrew, used to install python3 from Terminal.
  • The Python extension by Microsoft, with the ID ms-python.python.
  • A folder for practice scripts, such as Documents/python-practice.

How to Run a Python file in VS Code on Mac in VS Code on a Mac

  1. Install Visual Studio Code

    Download the VS Code .dmg from Microsoft's Mac setup page. Open it and drag Visual Studio Code into your Applications folder. Open VS Code once to confirm it starts.

    Tip: Microsoft ships Universal, Intel, and Apple silicon builds, so one download covers both kinds of Mac.

  2. Install the code command

    ⇧⌘P

    Press ⇧⌘P to open the Command Palette. Type Shell Command: Install 'code' command in PATH and press Return. Restart Terminal, then run code . in a folder to check it works.

    Tip: Insiders builds, or organizations that disable AI features, show a shorter label. Pick the one that mentions PATH.

  3. Install Python 3 with Homebrew

    Open Terminal and run brew install python3. When it finishes, run python3 --version and read the version it prints. Do not rely on the Python that came with macOS for this guide.

    Tip: If brew is not found, install Homebrew first, then open a new Terminal window.

  4. Install the Python extension

    Open the Extensions view from the Activity Bar on the left. Search for Python, choose the extension by Microsoft, and click Install. Its ID is ms-python.python.

    Tip: If several results look alike, search for ms-python.python to find the right one.

  5. Select your interpreter

    ⇧⌘P

    Press ⇧⌘P, type Python: Select Interpreter, and choose the Python 3 you installed with Homebrew. Check the bottom status bar. It should show the same version.

  6. Create hello.py

    Open the folder that will hold your script. In the Explorer, click the New File button on the folder's toolbar. Name the file hello.py and type print('Hello from VS Code').

    Tip: Keep the .py ending. VS Code uses it to recognize a Python file.

  7. Save the file

    ⌘S

    Press ⌘S to save before you run. A dot on the file tab means unsaved changes are still open.

  8. Click the play button

    Click the play button labeled Run Python File at the top right of the editor. VS Code opens a terminal, runs python3 hello.py, and prints the output in the terminal panel.

    Tip: If your version says Run Python File in Terminal, it is the same button.

  9. Try the right-click route

    Right-click in editorRun PythonRun Python File in Terminal

    Right-click inside the editor and choose Run Python, then Run Python File in Terminal. The file saves first. Use this route if the play button is missing or you want every run in the terminal.

  10. Run a selection with Shift+Enter

    ShiftEnter

    Select one line or a block of code, then press Shift+Enter. VS Code sends the selection to a Python terminal, so you can see results one step at a time.

  11. Start the debugger

    F5

    Click the gutter beside a line number, or press F9, to set a breakpoint. Press F5 and choose Python File. Execution pauses at your breakpoint.

    Tip: Press ⇧⌘F5 to restart the debug session, or ⇧F5 to stop it.

  12. Check which Python ran

    Add import sys and print(sys.executable) to the top of hello.py. Run it again. Compare the path it prints with the interpreter shown in the status bar.

    Tip: If the paths differ, select the interpreter again and open a new terminal.

Most people who search this question have the same problem. They installed VS Code, opened a .py file, and got stuck. The file either did not run, or the output went somewhere they could not see. This guide fixes that in one pass. You will set up Python, choose the interpreter VS Code uses, and run a file in several ways.

Developer typing Python code on a MacBook while running a file in VS Code
Writing and running a Python file on a Mac · Image by Yng_saad from Pixabay

What you need before you start

You need a Mac, Visual Studio Code, and Python 3 installed on purpose. Microsoft's macOS setup page lists Universal, Intel, and Apple silicon builds of VS Code. It does not state a minimum macOS version, so check your macOS version against the current VS Code docs if your Mac is older.

  • A Mac with Apple silicon or Intel. VS Code ships builds for both.
  • Visual Studio Code, stable release. The current stable release is 1.145.
  • Homebrew, used to install python3 from Terminal.
  • The Python extension by Microsoft, with the ID ms-python.python.
  • A folder for practice scripts, such as Documents/python-practice.

The list looks short, but the Python part trips up most people. Apple includes a Python with macOS. Microsoft's Python tutorial says that system Python is not supported. Install a separate Python 3 with Homebrew, and VS Code can use that one instead.

Install Python 3 with Homebrew, not the system Python

Open Terminal. Press ⌘Space, type Terminal, and press Return. You can also open Applications, then Utilities, then Terminal. Run brew install python3 and wait for it to finish.

Next, confirm the install. Run python3 --version. It prints the version of Python that your Terminal finds first. If the line starts with Python 3, you are set. If it says command not found, the Homebrew install did not finish, or the Terminal window was open before the install.

Three Terminal commands you will use in this guide.
CommandWhat it doesWhat you should see
brew install python3Installs Python 3 with HomebrewThe install finishes without errors
python3 --versionPrints the Python version your Terminal findsA line that starts with Python 3
python3 -m pip install numpyInstalls a package into the python3 you runA success message from pip

You will reuse all three commands. The first installs Python, the second checks it, and the third adds a package later in this guide. Keep the Terminal window open while you work through the steps.

Add the Python extension

The Python extension gives VS Code its run buttons, environment tools, and Python debugger. Open the Extensions view from the Activity Bar on the left. Search for Python, pick the extension by Microsoft, and check that its ID is ms-python.python before you install it.

Select the Python interpreter in VS Code

An interpreter is the Python program that runs your file. VS Code uses the interpreter you select. That choice drives the play button and the debugger, so it matters more than anything else on this page.

You can pick it in two ways. Press ⇧⌘P, type Python: Select Interpreter, and choose the Python 3 you installed with Homebrew. Or look at the bottom status bar, which shows the Python version, and click it to switch.

For a clean setup on one project, use Python: Create Environment from the Command Palette. Choose Venv, pick an interpreter, and VS Code creates an environment for the folder. Quick Create, started with the + in the Environment Managers view, names the environment .venv and uses the latest Python.

Run Python: Select Interpreter again after you install or upgrade Python. That confirms which copy VS Code will use. It is a quick habit that saves a lot of confusion later.

Create hello.py and click Run Python File

Open the folder that will hold your scripts with File > Open Folder. In the Explorer sidebar, click the New File button on the folder's toolbar, and name the file hello.py. Then type this line: print('Hello from VS Code')

Press ⌘S to save. Then click the play button labeled Run Python File at the top right of the editor. VS Code opens a terminal in the bottom panel, runs python3 hello.py, and prints Hello from VS Code there.

Microsoft uses two labels for this button. The tutorial calls it Run Python File. The quick start calls it Run Python File in Terminal. Both start the same run, so look for the play icon in the top right corner of the editor.

Try a second file to test input. Create greet.py with name = input('Your name: ') on one line and print('Hello, ' + name) on the next. Run it, type your name at the prompt in the terminal, and press Return.

Other ways to run a Python file in VS Code

  • Right-click in the editor and choose Run Python > Run Python File in Terminal. This saves the file first.
  • Select one or more lines and press Shift+Enter. VS Code sends the selection to a Python terminal.
  • Open the Command Palette with ⇧⌘P and run Python: Start Terminal REPL for an interactive Python prompt.
  • Open the integrated terminal with ⌃⇧` and type python3 hello.py yourself.

Shift+Enter is useful for testing one idea at a time. Smart Send can also send lines you did not mean to run. If that happens, set python.REPL.enableREPLSmartSend to false in your settings. Microsoft's tutorial gives this same fix.

Start Terminal REPL suits exploring a library. It gives you a prompt where each line runs as you type it, using the interpreter you selected. Use the play button when you want the whole file to run from the top.

MacBook on a desk with a code editor open for a Python file
A simple desk setup for Python on a Mac · Image by StockSnap from Pixabay

Check which Python actually ran

Your Terminal and VS Code can use different Pythons. The terminal runs whatever comes first on your PATH. VS Code runs the interpreter shown in the status bar. When those two differ, results look confusing, and a script can pass in one place and fail in the other.

To see the truth, add two lines to the top of hello.py: import sys and print(sys.executable). Run the file. The path it prints is the interpreter that ran your code. Compare that path with the version shown in the status bar.

If the two do not match, select the interpreter again with Python: Select Interpreter. Then open a new terminal, because a terminal that was already open can keep an older Python on its path.

Run with the debugger when a script misbehaves

The play button runs your file from top to bottom and then stops. The debugger pauses at lines you choose, so you can watch values change. Press F9 on a line to set a breakpoint. Then press F5 and choose Python File.

Once the run pauses, press F10 to step over a line and F11 to step into a function. Press ⇧F11 to step out of the current function. This helps when a script has too many print calls to read.

Debug shortcuts from Microsoft's Python tutorial.
ActionShortcutWhen you use it
Toggle breakpointF9Pause on a line
Start debuggingF5Run the file with the debugger
Step overF10Run the current line, then stop on the next
Step intoF11Enter a function on the current line
Step out⇧F11Finish the current function and return
Restart⇧⌘F5Start the debug session again
Stop⇧F5End the debug session

Install a package before you import it

If a script imports a package that is not installed, Python stops with ModuleNotFoundError. The error means the selected interpreter does not have that package. Your Mac may have it in another Python, but VS Code does not use that one.

Install the package into the selected interpreter. In the Python sidebar, open Environment Managers, right-click your environment, and choose Manage Packages. Or press ⌃⇧` to open a terminal and run python3 -m pip install numpy.

Try it on hello.py. Add import numpy on the first line and run the file. You should see ModuleNotFoundError. Install numpy, run again, and the error should go away.

Common mistakes that stop a script from running

  • Running an unsaved file. Save with ⌘S first, or use Run Python File in Terminal, which saves for you.
  • Running the wrong interpreter. Check the version in the bottom status bar before you click play.
  • Using a Python installed while VS Code was open. Restart VS Code, then try again.
  • Getting an unwanted completion after typing as in an import. Type a space before you press Return.
  • Assuming the system Python is fine. Microsoft says it is not supported, so use Homebrew.
  • Expecting the web version to match the desktop app. It has real limits, covered below.

Most failures come from one of these. Check the status bar first. It shows the active interpreter at a glance, and that answers most questions before you dig into settings.

Running Python in the browser instead

Microsoft also documents an experimental Python for the Web option. You open insiders.vscode.dev with ?vscode-coi= added to the address, in Edge or Chrome. The source must be local, or a GitHub repository read through the GitHub Repositories extension.

The limits matter. The web version has no socket support, no thread or async support, no pip support, and no native Python modules. Use the desktop app on your Mac for anything that needs packages or networking.

Check your VS Code version

Microsoft's updates page lists 1.145 as the latest stable release, dated November 4, 2026. It also lists 1.144 and 1.143 before it, but it does not show their dates. Microsoft's pages do not describe a Mac-specific menu change in that range.

75.9%

of all respondents in the 2025 Stack Overflow Developer Survey use Visual Studio Code.

Stack Overflow Developer Survey 2025: Technology

57.9%

of the same 2025 respondents use Python.

Stack Overflow Developer Survey 2025: Technology

1.145

is the latest stable VS Code release, dated November 4, 2026.

Visual Studio Code Updates

Labels do shift between releases. If your window says something slightly different, look for the same idea: the play button, the Command Palette, or the status bar. The steps still apply when the wording moves.

Where to go next

Once the play button works, learn the integrated terminal. It is where your script output lives, and you can run scripts from it. Open it with ⌃⇧` and read the integrated terminal guide.

If you want to run scripts from any folder, install the code command first. The install the code command guide covers the Command Palette steps. Then use open a folder from the terminal to start a project from the shell.

Add extensions carefully. Read how to install an extension in VS Code on Mac before you add a second one, so you know where each setting lives.

Programmer checking Python output in a terminal panel on a Mac
Checking script output in the terminal · Image by StuBaileyPhoto from Pixabay

VS Code shortcuts for this on Mac

VS Code keyboard shortcuts on Mac
To do thisPress
Open the Command Palette⇧⌘P
Save the current file⌘S
Run selection or line in Python terminalShiftEnter
Start debugging with Python FileF5
Toggle a breakpointF9
Step overF10
Step intoF11
Step out⇧F11
Restart the debug session⇧⌘F5
Stop the debug session⇧F5

If it does not work

python3: command not found in the terminal
Install Python 3 with brew install python3, then restart VS Code and open a new terminal. Select the Homebrew Python as your interpreter.
ModuleNotFoundError when you import a package
The package is missing from the selected interpreter. Install it with python3 -m pip install package-name in the same environment, then run the file again.
A new Python does not appear in the interpreter list
Refresh environment discovery or restart VS Code. If it still does not appear, add its folder to workspaceSearchPaths or globalSearchPaths in settings.
Shift+Enter sends extra lines you did not select
Set python.REPL.enableREPLSmartSend to false in your settings, then try the selection again.
Typing as in an import triggers an unwanted completion
Type a space before you press Return. The completion will not appear on the new line.
The play button does not appear
Confirm the file ends in .py and the Python extension is installed and enabled. Then use right-click > Run Python > Run Python File in Terminal as a fallback.

Faster with Lazur

Do it faster: ask Lazur while you are in VS Code

Hold ⌥ ⌘ and say what you want. Lazur sees your VS Code window. Lazur draws a circle and a label around the button or menu you need.

  • 1

    Hold ⌥⌘ and talk

  • 2

    Lazur draws a circle and a label around the button or menu you need.

  • 3

    You stay in VS Code. Nothing to copy into a chat window.

Free for 3 days, then $18/month. Download for Mac

You say“Where's the run button?”

Lazur · points at itLazur circles the Run Python File button at the top right of the editor and labels it, so you can click it yourself.

VS Code
ExplorerSearchRun Python FileRight hereSource ControlRun

Questions people ask

Can I run a Python file without the play button?

Yes. Right-click in the editor and choose Run Python > Run Python File in Terminal. You can also open the integrated terminal with ⌃⇧` and type python3 hello.py yourself.

Why does my Mac say python3: command not found in VS Code?

The usual cause is that Python 3 is not installed with Homebrew yet. Run brew install python3, then restart VS Code or open a new terminal. Select that Python as your interpreter after the install.

Is there a Mac shortcut to run a Python file?

Microsoft's pages do not list a shortcut for the play button. Shift+Enter runs a selection, and F5 starts debugging. Check the macOS shortcut reference PDF linked from the keybindings page before you rely on any other key.

Should I use the Python that comes with macOS?

Microsoft's Python tutorial says the macOS system Python is not supported. Install Python 3 with Homebrew, then select it as your interpreter in VS Code.

Why does an import still fail after I installed a package?

The package went into a different interpreter. Check the status bar, then install the package into the selected one with Manage Packages or python3 -m pip install package-name.

Can I run Python in the browser instead?

Only through the experimental Python for the Web option at insiders.vscode.dev, with ?vscode-coi= added to the address. It has no socket, thread or async, pip, or native module support, so use the desktop app for real projects.

Which VS Code version should I install?

Use the latest stable release. Microsoft's updates page lists 1.145, dated November 4, 2026, as the current stable version.

Why does the button label differ from this guide?

Microsoft's tutorial and quick start use different labels for the same play button. Look for the play icon at the top right of the editor, and check the tooltip if you are unsure.

Sources

  1. Python in Visual Studio Code (official tutorial) · Microsoft / Visual Studio Code · checked 2026-11-09
  2. Python quick start (Visual Studio Code) · Microsoft / Visual Studio Code · checked 2026-11-09
  3. Python environments in VS Code · Microsoft / Visual Studio Code · checked 2026-11-09
  4. Python for the Web (experimental) · Microsoft / Visual Studio Code · checked 2026-11-09
  5. Key bindings for Visual Studio Code · Microsoft / Visual Studio Code · checked 2026-11-09
  6. Setting up VS Code on macOS · Microsoft / Visual Studio Code · checked 2026-11-09
  7. Visual Studio Code Updates · Microsoft / Visual Studio Code · checked 2026-11-09
  8. Stack Overflow Developer Survey 2025: Technology · Stack Overflow · checked 2026-11-09

Try Lazur free for 3 days

Hold a key and ask. Lazur sees your screen, points at the button and talks you through it, in any Mac app. No credit card.