gpt4 book ai didi

python - 使用 SublimREPL 插件更改用于评估文件的 Python 版本

转载 作者:太空狗 更新时间:2023-10-30 01:20:24 25 4
gpt4 key购买 nike

我在 Mac OS X El Capitan 上使用 Sublim Text 3。我需要做的是在 Sublime Text 3 中评估 Python 文件。

我已经安装了 Package ControlSublimREPL 插件。

我设置了一个 2 行布局(View > Layout > Rows: 2)以便在屏幕的第二部分显示 Python 解释器。

然后我使用 Tools > Command Palette... > SublimeREPL: Python 启动 Python 解释器。

enter image description here

解释器正确启动,我明白了:

enter image description here

我找不到如何启动我手动下载的 Python 3.5(因此安装在 /usr/local/bin/)。我试图修改此文件:/Library/Application Support/Sublime Text 3/Packages/SublimeREPL/Config/Python/Main.sublime-menu 遵循 this post说明,但这并没有改变任何东西(Python 2.7.10 仍然启动)。

这是我的 Main.sublime-menu 的内容:

[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "R",
"id": "SublimeREPL",
"children":
[
{"caption": "Python",
"id": "Python",

"children":[
{"command": "repl_open",
"caption": "Python",
"id": "repl_python",
"mnemonic": "P",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-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": "Python - virtualenv"},
{"command": "repl_open",
"caption": "Python - PDB current file",
"id": "repl_python_pdb",
"mnemonic": "D",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-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": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "R",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
{"command": "repl_open",
"caption": "Python - IPython",
"id": "repl_python_ipython",
"mnemonic": "I",
"args": {
"type": "subprocess",
"encoding": "utf8",
"autocomplete_server": true,
"cmd": {
"osx": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"linux": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"windows": ["python", "-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"
}
}
}
]}
]
}]
}
]

还在关注this post建议,我修改了下面的部分代码,但在文件夹/usr/local/bin/中找不到任何exe文件:

{"command": "repl_open",
"caption": "Python - PDB current file",
"id": "repl_python_pdb",
"mnemonic": "D",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["/usr/local/bin/python3", "-i", "-u", "-m", "pdb", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}

当我按下 Ctrl + , + f(根据 doc )时,解释器仍然以 Python 2.7.10 启动.

最佳答案

看来您正在修改不正确的配置文件,可能有几件事导致了问题。

I then launch the Python interpreter with Tools > Command Palette... > SublimeREPL: Python

没有命令面板项“SublimeREPL: Python”,所以我假设您指的是 Tools > SublimeREPL > Python > Python。这会在类似以下内容的选项卡中打开:

# *REPL* [python]
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

事实上 Tools > SublimeREPL > Python 显示了一个类似下面的菜单:

Python - execnet
Python
Python - virtualen
Python - PDB current file
Python - RUN current file
Python - IPython

到目前为止一切顺利。但是如何更改Python版本呢?

理想情况下,我们可以配置全局 python 来使用(这似乎不可能)或向上面描述的菜单添加版本变体(这似乎也不可能)。

最直接的解决方法是添加自定义版本变体。

创建一个名为 Packages/User/Main.sublime-menu 的文件(如果它不存在)。通过 Menu > Preferences > Browse Packages... 找到用户包目录。并在该文件中创建您的菜单。此菜单将添加到现有菜单。

例如:

Packages/User/Main.sublime-menu

[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL Variants",
"id": "SublimeREPLVariants",
"children":
[
{
"command": "repl_open",
"caption": "Python - PDB current file",
"id": "repl_python_pdb",
"mnemonic": "D",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["/usr/bin/python3", "-i", "-u", "-m", "pdb", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
]
}]
}
]

重要的是:

  1. 标题和 ID 与任何其他菜单不同,否则它将替换其他菜单,因此我将上面的菜单命名为“SublimeREPL Variants”。

  2. “cmd”使用有效二进制文件的绝对路径。您可以使用 which:

    这样的命令检查您是否使用了正确的路径

找到 Python 的位置,通过它:

    $ which python
/usr/bin/python

$ which python3
/usr/bin/python3

$ which python2
/usr/bin/python2

另见 Possible to switch between python 2 and 3 in Sublime Text 3 build systems? (Windows)了解更多详情。

关于python - 使用 SublimREPL 插件更改用于评估文件的 Python 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40016838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com