I am currently trying to change my default Python version to Python3. This proves to be harder than expected. I have already tried the following things:
alias python python3
but this seems to just change it for the running Terminal sessionln -s -f /opt/homebrew/bin/python3 /usr/bin/python
to change the directories but it returned ln: /usr/bin/python: Operation not permitted
to deal with this problem I have already given the Terminal full access to the local harddrive but it is still not working properly
Hoping for some advise, thanks in advance
First make sure the installed version is linked:
brew link python
then on your .bash_profile
or .bashrc
( .zshrc
if you're using zsh) write this:
export PATH="/usr/local/opt/python@X.Y/libexec/bin:$PATH"
change X
and Y
to your python version
I think it's easier to just change your user shell environment instead of changing the system level environment.
vi ~/.bash
Then type
alias python=python3
Save your file by pressing Esc
-> type :wq
Update your shell environment
source ~/.bash
Check your Python version.
python -V
Final result
Python 3.9.10
This works in my past few versions MacOS.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.