Search

Python Execution Error in MacBook VSCode (python: command not found)

When trying to run Python code in the VSCode editor on macOS, the following error occurred:
[Running] python -u "/Users/hyunwoochoi/Desktop/github/CodingInterview/LeetCode/Easy/13. Roman to Integer.py" /bin/sh: python: command not found [Done] exited with code=127 in 0.012 seconds
Bash
복사
After searching online, I found that this happens because the python command cannot be found on macOS.
On macOS, Python is often run using python3 instead of python.

Why does this happen?

On macOS 12 and later, Python 2 has been completely removed.
Even after installing Python 3, the python command is not automatically registered; you can only use python3.
VSCode’s Python execution command is set to python, so it cannot be found.

How to fix it

Method 1 - Configure VSCode to use python3

1.
Open the Command Palette in VSCode (⌘ + Shift + P)
2.
Search for "Python: Select Interpreter"
3.
Select the path to your installed Python 3 (e.g., /usr/local/bin/python3 or /opt/homebrew/bin/python3)

Method 2 - Link the python command to python3 (Symbolic Link)

In the terminal:
which python3 # Check the path of python3 # Example: /opt/homebrew/bin/python3 sudo ln -s $(which python3) /usr/local/bin/python
Bash
복사
This will make the python command run python3.
In my case, running which python3 to check the installed Python path returned:
/Library/Frameworks/Python.framework/Versions/3.13/bin/python3
Bash
복사

Method 3 - Change the execution command in VSCode

1.
Open the Command Palette in VSCode
⌘ + Shift + P
2.
Search for Preferences: Open Settings (JSON)
3.
Click to open settings.json
Add the following to your settings.json file
"code-runner.executorMap": { "python": "python3 -u" }
JSON
복사
File name to modify : settings.json
This way, when you use Run Code, it will execute with python3.