修长城

Mac上安装python3并设置SublimeREPL插件默认运

2018-02-09  本文已影响0人  老兵一枚

1、安装python3

$ brew search python
$ brew install python3

这里安装完后不需要单独添加环境变量,程序已经处理好,可以直接运行python3命令。

$ which python
/usr/bin/python

$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

2、安装REPL插件,并设置快捷键绑定。

image

打开后,搜索 SublimeREPL 安装即可。

设置快捷键:

Preferences -> Key Bindings

[   
    {"keys":["f1"],
    "caption": "SublimeREPL: Python - RUN current file",
    "command": "run_existing_window_command", "args":
    {"id": "repl_python_run",
    "file": "config/Python/Main.sublime-menu"}},

    {"keys":["f2"],
    "caption": "SublimeREPL: Python",
    "command": "run_existing_window_command", "args":
    {"id": "repl_python",
    "file": "config/Python/Main.sublime-menu"}}
]

这里我设置的 F1 运行代码,F2 打开终端。

3、按 F2 运行终端,发现默认集成的是 python2,手动改成 pyhton3,方法如下:

$ sudo find / -iname 'Main.sublime-menu'
$ vim /Users/keithtt/Library/Application\ Support/Sublime\ Text\ 3/Packages/SublimeREPL/config/Python/Main.sublime-menu

"cmd": ["python3", "-i", "-u"],
"cmd": ["python3", "-i", "-u", "-m", "pdb", "$file_basename"],
"cmd": ["python3", "-u", "$file_basename"],
"cmd": {
    "osx": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
    "linux": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
    "windows": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
},

将该文件中调用 python 命令的地方全部改成 python3 即可。

改完之后再次按 F2 运行终端,效果如下:

image
上一篇下一篇

猜你喜欢

热点阅读