- 操作系统:Mac10.11.5
- python2.7.13
- python3.6.1
安装python2:
brew install python
安装python3:
brew install python3
此时,命令行输入python3则打开python3,输入python则打开python2。
利用pip安装 ipython
sudo pip install ipython sudo pip3 install ipython
用pip安装ipython则是安装到python2的site-packages中,同理用pip3则是安装到python3的site-packages中。
进入/usr/local/bin目录下,可以看到ipython文件,用vi打开:
sudo vi ipython
#!/usr/local/opt/python/bin/python2.7 # -*- coding: utf-8 -*- import re import sys from IPython import start_ipython if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script.pyw?|.exe)?$', '', sys.argv[0]) sys.exit(start_ipython())
#!/usr/local/opt/python/bin/python2.7这个目录就是指向python的版本,
例如我要定向成python3可以修改该成#!/usr/local/opt/python3/bin/python3.6
这样ipython这个命令打开的ipython指向的python版本就是python3了。为了方便我们可以复制这个文件为ipython3,把ipython3这个命令文件指向python3版本,这样在终端输入ipython打开的就是python2,输入ipython3打开的就是python3,是不是很方便!