gpt4 book ai didi

python - python-mode、ipython、(ipython.el) 版本/发行版和 init.el/.emacs.d 代码的组合如何工作?

转载 作者:太空狗 更新时间:2023-10-30 00:11:11 27 4
gpt4 key购买 nike

我的目标是使用 Emacs 24 作为我的 python 编辑器(还有一个 Matlab 和 R 编辑器,但这不是我的问题)。

(如果我遗漏了任何信息或者我没有清楚地说明什么,请告诉我。)

我已经能够以这样的方式设置我的包和我的 init.el 文件,以便我能够获得选项卡完成、正确的突出显示和 Python 的片段。我使用 python-mode.el 作为我的 python 模式。
问题一切都围绕着这个:我想使用 ipython 作为我的 python shell,以便在调试脚本时使用它的选项卡完成功能。

  • 但是,当我启动 ipython(使用 M-x ipython)时,我没有选项卡完成。此外,它不会显示“[1] in:”,但会显示“[1] out:”。
  • 我想让 ipython 成为我在 Emacs 中的默认 shell。但是,这方面的尝试失败了(例如,将 C:\PATH\TO\IPython.exe 设置为 py-python-command)。
  • 当我尝试使用 C-c C-c 运行我的 python 脚本时,它使用普通的 Python 运行,并且确实停在我告诉调试器停止的位置(我使用 ipdb.set_trace)。但是,当我使用另一种应该启动 IPython 的命令时(例如将区域设置为我的整个脚本并运行 py-execute-region-ipython)IPython 不起作用。它确实启动了一个 IPython shell,或者至少看起来是这样,但我可以像输入文本编辑器一样输入 shell(仅供引用:在迷你缓冲区中它显示“Comint:run shell-compile”)。

  • 我的问题 是:
    我的 init.el 文件中的包版本和 lisp 代码的什么组合应该允许我使用带有制表符完成功能的 ipython 作为我在 Emacs 中的默认 shell?如有必要,我愿意降级某些软件包。

    额外信息 :

    从我在 Python-mode.el 的项目页面上读到的内容,我了解到这个包的最新版本仍然存在一些关于 IPython 的错误,因此可能需要使用旧版本。
    我一直在谷歌上搜索解决方案,但一直找不到适合我的解决方案。

    我在跑
  • python模式6.1.3,
  • ipython 1.1.0
  • 我尝试了来自 https://raw.github.com/ipython/ipython/d2d967af9de6081c8cdbab0eab1115164e5e72bd/docs/emacs/ipython.el 的 ipython.el ,但是从接触python-mode.el的开发者来看这个好像已经弃用了,并没有集成到python-mode.el中。
  • GNU Emacs 24.3.1 (i386-mingw-nt6.1.7601) of 2013-03-17 on MARVIN
  • 视窗 7 64 位。

  • 我的 init.el 看起来像(python 的东西在底部):


    ;; Requisites: Emacs >= 24
    (require 'package)
    (package-initialize)

    (add-to-list 'package-archives
    '("melpa" . "http://melpa.milkbox.net/packages/"))
    (add-to-list 'package-archives
    '("marmalade" . "http://marmalade-repo.org/packages/") t)

    (package-refresh-contents)

    (defun install-if-needed (package)
    (unless (package-installed-p package)
    (package-install package)))

    ;; make more packages available with the package installer -->
    ;; removed python mode since the version I got had errors
    (setq to-install
    '(
    ;python-mode
    magit yasnippet jedi auto-complete autopair find-file-in-repository flycheck))

    (mapc 'install-if-needed to-install)


    ;;------------R STUFF-----------

    (add-to-list 'load-path "C:\\emacs-24.3\\site-lisp\\ess-13.09-1")
    (setq ess-use-auto-complete t)
    (load "ess-site")

    ;;------------MatLab STUFF-----------
    ; add folder of matlab-mode.el
    (add-to-list 'load-path "C:\\Users\\Rob Ter Horst\\AppData\\Roaming\\.emacs.d\\elpa\\matlab-mode-20130829.142")
    (load-library "matlab-load")

    (matlab-cedet-setup)


    (setq matlab-show-mlint-warnings t)
    (add-hook 'matlab-mode-hook 'auto-complete-mode)
    (add-hook 'matlab-mode-hook 'mlint-minor-mode)
    ;;------------GENERAL STUFF-----------

    ; Ido mode: Ido-powered versions of code. Most ido commands are named ido-xxxxx
    ; so find-file becomes ido-find-file, and so on.
    (setq ido-enable-flex-matching t)
    (setq ido-everywhere t)
    (ido-mode t)
    (global-linum-mode t)
    ;Use y or n always instead of yes/no
    (defalias 'yes-or-no-p 'y-or-n-p)

    ;; -------------------- extra nice things Andrea Crotti--------------------
    ;; use shift to move around windows
    (windmove-default-keybindings 'shift)
    (show-paren-mode t)
    ; Turn beep off
    (setq visible-bell nil)
    (custom-set-variables
    '(ansi-color-names-vector ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
    '(custom-enabled-themes (quote (wheatgrass))))
    (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.
    )
    (put 'downcase-region 'disabled nil)

    ;;------------PYTHON STUFF-----------
    ;(require 'magit)
    ;(global-set-key "\C-xg" 'magit-status)

    (require 'auto-complete)
    (require 'autopair)
    (require 'yasnippet)
    (require 'jedi)

    ;yasnipped settings
    (setq yas-snippet-dirs
    '("C:\\Users\\Rob Ter Horst\\AppData\\Roaming\\.emacs.d\\elpa\\yasnippet-20140106.1009\\snippets"))
    (add-to-list 'load-path "C:\\Users\\Rob Ter Horst\\AppData\\Roaming\\.emacs.d\\elpa\\yasnippet-20140106.1009")

    (global-set-key [f7] 'find-file-in-repository)

    ; auto-complete mode extra settings
    (setq
    ac-auto-start 2
    ac-override-local-map nil
    ac-use-menu-map t
    ac-candidate-limit 20)

    ;; ;; Python mode settings
    (setq py-install-directory "C:\\Users\\Rob Ter Horst\\AppData\\Roaming\\.emacs.d\\self_installed\\python-mode.el-6.1.3")
    (add-to-list 'load-path py-install-directory)
    (add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
    (when (featurep 'python) (unload-feature 'python t))
    (require 'python-mode)

    (setq py-electric-colon-active t)
    (add-hook 'python-mode-hook 'autopair-mode)
    (add-hook 'python-mode-hook 'yas-minor-mode)
    (add-hook 'python-mode-hook 'auto-complete-mode)

    ;; ;; Jedi settings

    ;; It's also required to run "pip install --user jedi" and "pip
    ;; install --user epc" to get the Python side of the library work
    ;; correctly.
    ;; With the same interpreter you're using.

    ;; if you need to change your python intepreter, if you want to change it
    ;; (setq jedi:server-command
    ;; '("python2" "/home/andrea/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py"))

    (add-hook 'python-mode-hook
    (lambda ()
    (jedi:setup)
    (jedi:ac-setup)
    (local-set-key "\C-cd" 'jedi:show-doc)
    (local-set-key (kbd "M-SPC") 'jedi:complete)
    (local-set-key (kbd "M-.") 'jedi:goto-definition)))

    ; ipython settings

    (setq py-python-command "C:\\Python27\\Scripts\\ipython.exe")
    (setq py-complete-function 'ipython-complete
    py-shell-complete-function 'ipython-complete
    py-shell-name "ipython"
    py-which-bufname "IPython")
    ;(require 'ipython)

    ;With tab autocompletion in ipdb I get an error that might be solved by changing this var
    ;the error: "variable binding depth exceeds max-specpdl-size"
    (setq max-specpdl-size 32000)

    ; Try to add flycheck --> flycheck causes emacs to become incredibly slow on big script with
    ; many style errors (as present in a lot of my older scripts, so I do not want to activate it
    ; by default
    ;(setq flycheck-highlighting-mode 'lines)
    ;(add-hook 'python-mode-hook 'global-flycheck-mode)
    ;(flycheck-select-checker 'python-flake8)
    ;(provide 'init-flycheck)

    (yas-reload-all)

    最佳答案

    使用 Emacs24,我使用默认的 python.el(不是 python-mode.el),它开始于 on github .

  • 当我用 python-shell-switch-to-shell 启动 ipython 时或 C-c C-p (Python 菜单 -> 启动解释器),我得到了 ipython。标签完成工作。
  • ipython 是默认的 Python 解释器(请参阅我的 init 文件)
  • 当我启动一个 ipython shell 时,我可以向它发送一个文件或选定的区域(菜单中可用的命令),并且它会得到正确的评估。

  • 作为旁注,您可以使用 jedi:setup 启动绝地自动补全功能。当你在 python shell 中时。它提供了带有参数帮助和文档的漂亮弹出窗口,您可以选择在点处(而不是在 3 个字符之后)触发它。见 IPython auto-completion emacs24 doesn't work .它可以被看作是对 ipython 的补充而不是替代。

    按照我的配置:
    ;; trying ipython tab completion: that works :)
    (setq
    python-shell-interpreter "ipython"
    python-shell-interpreter-args ""
    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"
    )

    取自 http://www.emacswiki.org/emacs/PythonProgrammingInEmacs#toc5

    希望这可以帮助。

    关于python - python-mode、ipython、(ipython.el) 版本/发行版和 init.el/.emacs.d 代码的组合如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21880950/

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