Use the Mac terminal to open python2 instead of python3 (a detailed solution in this article)
table of Contents
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.
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.
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,
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.
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.
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.
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.