On this instructional, we’ll discover the best way to configure your device to make use of the
python command as a substitute of
While you set up Python 3 or the most recent edition of Python for your Mac, it’s in most cases performed the use of the
python3 command. Alternatively, if you would like use Python 3 whilst working it with simply the
python command, this information is for you.
Earlier than we continue with the educational, I guess that you have already got Python put in for your Mac. In the event you haven’t put in it but, please consult with this information on the best way to set up Python for your Mac.
Let’s dive in.
Mapping ‘python’ to ‘python3’
To modify the default
python3 command for your Mac to indicate to
python, you’ll be able to create an alias. That is finished through enhancing your shell’s configuration record. Right here’s the best way to do it:
Step 1: Open Terminal
You’ll be able to to find it within the Programs folder beneath Utilities, or seek for it the use of Highlight.
Step 2: Resolve Your Shell
macOS makes use of both bash or zsh because the default shell. You’ll be able to resolve which one you’re the use of through working
echo $SHELL within the terminal.
Step 3: Edit the Configuration Report
- In the event you’re the use of bash, you’ll edit
- In the event you’re the use of zsh, you’ll edit
Step 4: Upload an Alias
Open the fitting record in a textual content editor, corresponding to Nano, through typing
nano ~/.bash_profile or
nano ~/.zshrc (relying for your shell).
Upload the next line to the record:
Save and shut the record (in Nano, that is finished through urgent Ctrl + X , then Y to verify, and Input to go out).
Step 5: Practice the Adjustments
For the adjustments to take impact, you both wish to restart your terminal or supply the profile record through typing
supply ~/.bash_profile or
After doing this, whilst you sort python for your terminal, it will have to now use
python3. Take into account that this transformation is particular on your consumer account at the Mac, and it received’t impact system-level Python configurations.
Didn’t Paintings? Take a look at the Following:
If surroundings an alias didn’t paintings, there could be a couple of the reason why. Let’s check out a distinct way:
1. Take a look at Your Shell Once more
First, be sure that you edited the proper configuration record in your shell. Run
echo $SHELL within the Terminal to verify your shell. If it’s zsh, the record is
~/.zshrc. For bash, it’s one among
2. Check Alias Syntax
Make certain that the alias line for your configuration record is strictly as follows:
There will have to be no further areas or characters.
3. Recheck Configuration Report
Double-check that you simply stored the adjustments to the configuration record.
4. Supply the Configuration Report
supply ~/.zshrc (for zsh) or
supply ~/.bash_profile (for bash) to use the adjustments instantly. If this step is overlooked, the alias received’t paintings till the following time you log in.
5. Restart Terminal
After sourcing the configuration record, shut and reopen the Terminal. Infrequently a recent get started is wanted.
6. Take a look at for Conflicts
When you have different configuration information (like
~/.profile), they could warfare. Take a look at the ones information for any current python
7. Take a look at Your PATH
Make certain that the listing containing the
python3 executable is for your
echo $PATH to peer your present
8. Check the Alias Immediately
Check out surroundings the alias without delay within the Terminal (no longer throughout the record) to peer if it really works:
alias python='python3' python --version
If this works, the problem is most probably with how the configuration record is being sourced.
9. Use Absolute Trail
If the alias nonetheless doesn’t paintings, you’ll be able to use absolutely the trail to the
python3 executable. In finding it the use of which python3, after which set the alias with that trail:
alias python='/absolute/trail/to/python3'WordPress Website Development Source: https://www.hongkiat.com/blog/map-python-python3/