Emacs Python模式和执行命令

时间:2013-03-08 02:09:59

标签: emacs python-2.7 emacs24 python-mode

我在C:\Program Files(x64)C:\Python27

下的python2.7上安装了emacs24

我尝试安装python模式,以便从emacs向解释器发送命令。我在Users/myname/.emacs.d中的init.el文件:

(setq py-install-directory "~/.emacs.d/python-mode.el-6.1.1")
(add-to-list 'load-path py-install-directory)
(require 'python-mode)
(setq py-shell-name "C:\Python27\python.exe")

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(py-shell-name "C:\\Python27\\python.exe"))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

我已将python模式文件放在:C:\Users\myname\.emacs.d\python-mode.el-6.1.1

通过选择PyShell>可以在缓冲区中形成交互式python会话。菜单中的默认Intepreter选项,但是如果我打开一个.py文件并尝试运行一个hellow世界,例如转到菜单PyExec>执行声明我得到这种性质的错误:

Opening output file: no such file or directory, c:/Users/Ben/AppData/Local/Temp/C-/Python27/python.exe-705218Y.py

如何设置以便我可以编辑python代码,然后在没有此错误的情况下将行发送到另一个缓冲区中的python解释器?

1 个答案:

答案 0 :(得分:3)

您正在使用setqcustom-set-variables设置py-shell-name。如果我没记错的话,custom-set-variables如果在它之前使用setq则不起作用。此外,当您在字符串文字中写入时,您需要转义反斜杠。使用以下其中一项可以解决您的问题。

要使用setq,请修复反斜杠:

(setq py-install-directory "~/.emacs.d/python-mode.el-6.1.1")
(add-to-list 'load-path py-install-directory)
(require 'python-mode)
(setq py-shell-name "C:\\Python27\\python.exe")

要使用custom-set-variables,只需删除setq

(setq py-install-directory "~/.emacs.d/python-mode.el-6.1.1")
(add-to-list 'load-path py-install-directory)
(require 'python-mode)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(py-shell-name "C:\\Python27\\python.exe"))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )