
- Mac中在Sublime Text3上初次配置交互环境的方法
- Mac中在Sublime Text上如何通过conda切换不同Python环境?
- Mac中如何在Sublime Text3上通过REPL插件切换不同Anconda下的Python开发环境?
Mac中初次在Sublime text3下通过REPL插件配置交互环境的具体方法,参考我之前写的博文【Mac中如何配置Sublime text3的交互环境和实现在Sublime text3中使用pdb模块调试代码】
Mac中在Sublime Text上如何通过conda切换不同Python环境?关于Mac中在Sublime Text上如何通过conda切换不同Python环境?,参考我之前写的博文Mac在已安装Python3.9的情况下利用miniconda配置【Python3.7+TensorFlow1.14环境】+ Sublime Text如何通过conda切换不同Python环境
Mac中如何在Sublime Text3上通过REPL插件切换不同Anconda下的Python开发环境?问题描述:
由于不同的框架脚本可能需要在不同的Python环境下运行、调试,目前本人认为较轻巧、易用的一款可实现交互式代码调试的编译器是通过Sublime Text3上的REPL插件实现。不过默认情况下,REPL插件关联启动的Python环境是固定的,而实际需求对Python环境是变化多端的,因此,需要设法实现随意配置、切换Sublime Text3上的REPL插件关联的Python运行环境。
解决方案:
- 打开sublime text → Preferences → Browse packages → SublimeREPL → config,找到 config文件夹;
- 在config文件夹下,新建文件夹Python3.6(命名可以根据anaconda下自己的创建的python版本来定义);
- 将config文件夹下 → Python文件夹下的所有文件复制到新建的文件夹Python3.6下;
- 修改配置文件,打开文件夹Python3.6下的Main.sublime-menu文件,替换所有的Python为Python3.6(改个名字)除了以下2种情况中的Python不替换。
"syntax": "Packages/Python/Python.tmLanguage",
和
"extend_env": {"PYTHONIOENCODING": "utf-8"}
- 打开Main.sublime-menu文件,将所有“cmd”:后的路径改为anaconda的python3.6环境路径
"cmd": ["/Users/zhang/opt/miniconda3/envs/py36/bin/python3.6", "-i", "-u"]
- 打开Default.sublime-commands文件,替换所有Python为Python3.6
- 打开sublime text → Preference → key bindings添加如下代码,设置REPL脚本运行的快捷键,如F1:
{"keys":["f1"],
"caption": "SublimeREPL: Python3.6",
"command": "run_existing_window_command", "args":
{"id": "repl_Python3.6",
"file": "config/Python3.6/Main.sublime-menu"}},
- 重启sublime text,试下你的F1即可进入anaconda3.6环境!
备注:
我的Main.sublime-menu文件,修改后全文:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "R",
"id": "SublimeREPL",
"children":
[
{"caption": "Python3.6",
"id": "Python3.6",
"children":[
{"command": "repl_open",
"caption": "Python3.6",
"id": "repl_python",
"mnemonic": "P",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["/Users/zhang/opt/miniconda3/envs/py36/bin/python3.6", "-i", "-u"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
{"command": "python_virtualenv_repl",
"id": "python_virtualenv_repl",
"caption": "Python3.6 - virtualenv"},
{"command": "repl_open",
"caption": "Python3.6 - PDB current file",
"id": "repl_python_pdb",
"mnemonic": "D",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["/Users/zhang/opt/miniconda3/envs/py36/bin/python3.6", "-i", "-u", "-m", "pdb", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
{"command": "repl_open",
"caption": "Python3.6 - RUN current file",
"id": "repl_python_run",
"mnemonic": "R",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["/Users/zhang/opt/miniconda3/envs/py36/bin/python3.6", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
{"command": "repl_open",
"caption": "Python3.6 - IPython",
"id": "repl_python_ipython",
"mnemonic": "I",
"args": {
"type": "subprocess",
"encoding": "utf8",
"autocomplete_server": true,
"cmd": {
"osx": ["/Users/zhang/opt/miniconda3/envs/py36/bin/python3.6", "-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"]
},
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {
"PYTHONIOENCODING": "utf-8",
"SUBLIMEREPL_EDITOR": "$editor"
}
}
}
]}
]
}]
}
]
我的Default.sublime-commands文件修改后的全文;
[
{
"caption": "SublimeREPL: Python3.6",
"command": "run_existing_window_command", "args":
{
"id": "repl_python",
"file": "config/Python3.6/Main.sublime-menu"
}
},
{
"caption": "SublimeREPL: Python3.6 - PDB current file",
"command": "run_existing_window_command", "args":
{
"id": "repl_python_pdb",
"file": "config/Python3.6/Main.sublime-menu"
}
},
{
"caption": "SublimeREPL: Python3.6 - RUN current file",
"command": "run_existing_window_command", "args":
{
"id": "repl_python_run",
"file": "config/Python3.6/Main.sublime-menu"
}
},
{
"command": "python_virtualenv_repl",
"caption": "SublimeREPL: Python3.6 - virtualenv"
},
{
"caption": "SublimeREPL: Python3.6 - IPython3.6",
"command": "run_existing_window_command", "args":
{
"id": "repl_python_ipython",
"file": "config/Python3.6/Main.sublime-menu"
}
}
]
参考链接:Sublime Text 3 以sublimeREPL配置Anaconda中python环境
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)