Use the Mac terminal to open python3 instead of python2 (a detailed solution in this article)

Use the Mac terminal to open python2 instead of python3 (a detailed solution in this article)

Preface

This article is written with reference to https://www.jianshu.com/p/bdb19e6ce03f .
If you enter python in the terminal of your mac, like me, it is python2 as shown in the figure.
python2.7
Then you can continue to look down

Specific steps

Enter python3, see if you have python3, install it if you don’t have one.
If so, it will be like this.
Insert picture description here
So since there is python3, where is python3? And where is the previous python2?
The method to find them is as follows.

which python
which python3
which python2

My results are shown in the figure,
Insert picture description here
so I found their location. Next, let's see where the default is.
Open the .bash_profile file in the terminal, that is, enter open .bash_profile

open .bash_profile

Will open a .bash_profile file, mine is like this, as shown in the figure.
Insert picture description here
Then finally add alias python="/usr/local/bin/python3", where "/usr/local/bin/python3" is the path that python3 knew before.

alias python="/usr/local/bin/python3"

After adding, as shown in the figure.
Insert picture description here
thencommand+sSave
and then we re-read the .bash_profile file in the terminal,
that is, enter
source .bash_profile in the terminal

source .bash_profile

Then we enter python in the terminal, the default will become python3. As shown.
Insert picture description here

note

If you import some libraries that should exist in this python3, but do not exist, you can refer to my previous article to increase the search path.
"Python SPYDER entry one (installation and increase search path) super detailed"

Concluding remarks

Like and follow if you have any help. Thank you all.
Watermelon 6's la la la

Guess you like

Origin blog.csdn.net/qq_37924224/article/details/109642307
Recommended