配置 .emacs 以使用 IPython 解释器

问题描述 投票:0回答:3

我是 lisp 新手,很难为 ipython 配置 emacs。我的 .emacs 文件的一部分如下所示:

;; Python mode settings
(require 'python-mode)
(add-to-list 'load-path "~/.emacs.d/elpa/")
(let ((default-directory "~/.emacs.d/elpa/"))
  (normal-top-level-add-to-load-path '("."))
  (normal-top-level-add-subdirs-to-load-path))

(autoload 'python-mode "python-mode" "Python Mode." t)
(add-to-list 'auto-mode-alist '("\\.py$\\'" . python-mode))
(add-to-list 'interpreter-mode-alist '("python" . python-mode))

(require 'ipython)

我从命令行窗口运行

emacs --debug -init
,并在启动 emacs 时收到以下错误消息:

Debugger entered--Lisp error: (wrong-type-argument listp "-i")
  nconc("-i" ("-colors" "LightBG"))

  eval-buffer(#<buffer  *load*-610080> nil "c:/Users/xxxx/AppData/Roaming/.emacs.d/elpa/python-mode-20150616.2346/ipython.el" nil t)  ; Reading at buffer position 9523
  load-with-code-conversion("c:/Users/xxxx/AppData/Roaming/.emacs.d/elpa/python-mode-20150616.2346/ipython.el" "c:/Users/xxxx/AppData/Roaming/.emacs.d/elpa/python-mode-20150616.2346/ipython.el" nil t)
  require(ipython)

这可能应该是非常明显的事情,但老实说不确定如何解决这个问题。如果您能指出正确的方向,那将非常有帮助。谢谢。

emacs ipython python-mode
3个回答
1
投票

似乎您正在使用 python-mode.el 中的 python-mode:无需对 IPython 进行特殊设置。不需要 ipython.el,它已经过时了。

py-shell-name
配置为“ipython”将使其成为默认 shell。 M-x
ipython
RET 应该开箱即用,也可以将内容发送到 ipython-commands。

对于覆盖默认值的特殊情况,请查看 README.org。


0
投票

尝试更改

ipython
命令行,如下所示:

(add-hook 'python-mode-hook
            (lambda ()
              ;You can uncomment next lines
              ;(set (make-variable-buffer-local 'beginning-of-defun-function)
              ;     'py-beginning-of-def-or-class)
              ;(setq outline-regexp "def\\|class ")
              ;(setq tab-width 4)
              ;(define-key py-mode-map "\C-c4" 'uncomment-region )
              ;(outline-minor-mode 1)
              ;(linum-mode 1)
              ;Ipython settings sections
              (require 'ipython)
              (setq-default py-shell-name "ipython")
              (setq-default py-which-bufname "IPython")
              (setq py-python-command-args '("--colors=linux")) ;Command line for run iPython
              ))

0
投票

我的

init.el
中有以下内容,使 ipython 成为默认的 python 解释器:

(setq
 python-shell-interpreter "ipython"
 python-shell-interpreter-args "-i --simple-prompt"
 python-shell-prompt-regexp "In \\[[0-9]+\\]: "
 python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
 python-shell-completion-setup-code
   "from IPython.core.completerlib import module_completion"
 python-shell-completion-module-string-code
   "';'.join(module_completion('''%s'''))\n"
 python-shell-completion-string-code
   "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")

要启动翻译器,您只需拨打

run-python

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.