我是 Emacs 的新手,我正在尝试设置我的 python 环境。到目前为止,我已经了解到在 python 缓冲区中使用“python-mode.el” C-c C-c 将当前缓冲区的内容加载到交互式 python shell 中,显然使用 what which python 产量。在我的例子中是 python 3.3.3。但是因为我需要一个 python 2.7 shell,所以我试图让 Emacs 在 C-c C-c 上生成这样一个 shell。不幸的是,我不知道该怎么做。将 py-shell-name 设置为 which python2.7 产生的结果(即 /usr/bin/python2.7)不起作用。如何让 Emacs 执行此操作,或者当我点击 C-c C-c 时如何追溯 Emacs 执行的内容?
请您参考如下方法:
python-mode.el,使用python2执行一个python缓冲区:
M-x py-execute-buffer-python2
或者将其放入 .emacs 文件中:
(custom-set-variables
'(py-force-py-shell-name-p t)
'(py-shell-name "python2"))
python-mode.el 在执行 py-execute-buffer 时检查 py-force-py-shell-name-p 变量(绑定(bind)到 C-c C-c 键),如果此变量设置为 true("t"),则使用保存在 py-shell-name 中的 python 解释器名称。
或者,可以在 M-x customize、Programming>Languages>Python Mode 中完成此自定义,在那里搜索“Py Force Py Shell”和“Py Shell Name”行。 它会将此自定义代码添加到您的 .emacs 文件中。
Emacs 帮助(描述功能):
C-h f py-execute-buffer TAB
您可以将 python 缓冲区中的选定区域发送给任何解释器:
C-u 3 M-x py-execute-region
Emacs 每次都会提示您输入要使用的 Python 解释器名称。 前缀数字参数可以是除 1 或 4 之外的任何数字,否则它将在没有提示的情况下使用默认解释器。
要在不同的 Python 解释器中执行缓冲区,您可以通过 C-x h 选择整个缓冲区,然后使用此前缀命令。
