If you are using zsh, you would edit ~/.zshrc.
Open the appropriate file in a text editor, such as Nano, by entering nano ~/.bash_profile or nano ~/.zshrc (depending on your shell).
Add the following line to the file: alias python='python3'.
Save and close the file (in Nano, this is done by pressing Ctrl + X , then Y to confirm and Enter to exit).
For the changes to take effect, you need to restart your terminal or source the profile file by entering source ~/.bash_profile or source ~/.zshrc.
After doing this, when you type python into your terminal it will use python3. Remember that this change is specific to your user account on the Mac and it will not affect system-level Python configuration.
If setting up an alias doesn't work, it could be for a number of reasons. Let's try another approach:
First, make sure you have edited the correct configuration file for your shell. Run echo $SHELL in Terminal to confirm your shell. If it is zsh, the file will be ~/.zshrc. For bash, it's one of ~/.bash_profile, ~/.bashrc, or ~/.profile.
Make sure that the alias line in your configuration file is exactly like this:
alias python='python3'
There should be no additional spaces or characters.
Double check that you have saved the changes to the configuration file.
Run source ~/.zshrc (for zsh) or source ~/.bash_profile (for bash) to apply the changes immediately. If this step is skipped, the alias will be inactive until your next login.
After locating the configuration file, close and reopen Terminal. Sometimes a new start is needed.
If you have other configuration files (like ~/.bashrc or ~/.profile), they may conflict. Check those files for any existing python aliases or PATH modifications.
Make sure that the directory containing the python3 executable is in your PATH. Run echo $PATH to see your current PATH.
Try setting the alias directly in Terminal (not through a file) to see if it works:
alias python='python3' python --version
If this method works, the problem may lie in how to source the configuration file.
If the alias still doesn't work, you can use the absolute path to the python3 executable. Find it using python3, then alias with that path:
alias python='/absolute/path/to/python3'