Making Python 3 Default in MacOS

Python users on the Mac are likely aware that Python is being deprecated from macOS 12.3 onward, and will no longer be preinstalled on the Mac. But Python remains an incredibly popular programming language, and if you rely on Python you’ll likely want to continue to have Python available in macOS. It’s easy to get Python 3 on the Mac, so let’s go a step further and show you how you can make Python 3 the new default Python version in macOS, whenever the python command is executed.

Installing Python 3 on the Mac

If you already installed Python 3 on the Mac using the official Python installer from here or Homebrew, you can skip this section.

If you haven’t installed Python 3 yet it’s easy to do so with a single homebrew command:

brew install python

This will install the latest Python 3 release available through HomeBrew. Again, you can also install it using the Python 3 installer, or even the MacAdmins Python release if you’d prefer.

How to Make Python 3 the Default in MacOS

We are assuming you’re using the default Zsh shell (or Oh My Zsh) and thus modifying .zshrc, but if you still use bash then you’d add the alias into .bashrc instead.

  1. From the Terminal, open zshrc in your text editor of choice, we’ll use nano for the sake of ease:
    nano ~/.zshrc
  2. Add the following alias at the bottom of the .zshrc file:
    alias python=/usr/local/bin/python3
  3. Hit Control-O and then Control-X to save the edit and then exit out of nano

Now you can confirm the alias worked by checking the python version:

$ python --version
Python 3.9.8

This should be the same response as if you type, since the python command has been aliased to python3:

python3 --version

Remember this is only an alias. If you continue to have the original Python 2.7.x release installed on the Mac, it remains accessible and usable by specifying the full path, like so:

/usr/bin/python

Keep in mind that in future versions of MacOS, Python 2.x will no longer be bundled.

We’re using aliases here in this example, but you can use a symbolic link linking /usr/bin/python3 to /usr/bin/python instead if you’d prefer to go that route.

What happened to Python in MacOS?

For those who aren’t aware, Apple has been warning for a while now that Python would be deprecated from future macOS versions, and that time has finally arrived with macOS Monterey 12.3 onward. This is found in the developer notes, listed under Deprecations:

Deprecations
Python 2.7 was removed from macOS in this update. Developers should use Python 3 or an alternative language instead. (39795874)

Thus if you are or were dependent on Python 2.7.x for any particular reason, you’ll either need to update your programs for Python 3 compatibility, maintain an older deprecated Python 2.x release (which is possible with Homebrew, etc), or rewrite everything and move on to another language entirely.

If you have any relevant thoughts, information, or experiences with Python in the latest macOS versions, share in the comments.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值