7

我正在尝试按照此处的说明使用果酱包管理器为 emacs 安装 Jedi - http://tkf.github.io/emacs-jedi/latest/。包管理器安装 Jedi 及其依赖项。但我无法使用以下方法安装 python 服务器:

M-x jedi:install-server

因为即使在 jedi 安装后重新启动 emacs 后该命令也不可用。唯一可用的命令是:

Possible completions are:
jedi:ac-setup   jedi:complete
jedi:dot-complete   jedi:get-in-function-call
jedi:goto-definition    jedi:goto-definition-next
jedi:goto-definition-pop-marker     jedi:setup
jedi:show-doc   jedi:show-jedi-version
jedi:start-dedicated-server     jedi:stop-server
jedi:toggle-debug-server

我的 .emacs 有以下内容:

(autoload 'jedi:setup "jedi" nil t)
(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:complete-on-dot t)

我在 Mac OS X 上使用 emacs。

在当前状态下,当我打开任何 python 文件(我使用 python 2.7)时,我看到以下内容自动出现在 minibuffer 中:

deferred error : (error Server may raise an error : Traceback (most recent call last):
  File "/Users/t_nithyanandan/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py", line 302, in <module>
    main()
  File "/Users/t_nithyanandan/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py", line 298, in main
    jedi_epc_server(**vars(ns))
  File "/Users/t_nithyanandan/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py", line 210, in jedi_epc_server
    import_jedi()
  File "/Users/t_nithyanandan/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py", line 249, in import_jedi
    import jedi
ImportError: No module named jedi
)

我尝试使用其他方法(例如 el-get 和手动安装绝地武士),但这些方法似乎还没有走这么远。我看到可用的绝地命令比上面列出的还要少。

有人可以帮助指出我缺少什么吗?

谢谢。

编辑:我想使用 Jedi 的主要目的是使用自动完成功能进行 python 编程,尽管我相信 Jedi 有许多强大的功能。出于这样的目的,python 服务器是必不可少的还是可以解决它?最后,当然,我想利用 Jedi 中的更多功能。

4

2 回答 2

10

感谢来自 emacs-jedi github 的 Chris 和 syohex 的帮助,我设法解决了这个问题。归功于他们将其追溯到绝地版本。

我只是链接了关于emacs-jedi 问题 #177的讨论,并粘贴了我发现的解决方法,包括我在此过程中遇到的其他问题。

我使用的是安装了旧版本的果酱版本。所以我卸载了 jedi 和相关的依赖项。我将我的存储库设置为 MELPA 并安装了更新版本的绝地。这使得命令

M-x jedi:install-server 

可用,而之前的情况并非如此。

但是,发出该命令会出错

python-environment--make-with-runner: Program named "virtualenv" does not exist.

我确保将 virtualenv 的位置添加到 .bashrc 中的 PATH 中。所以我查找了emacs-jedi 问题 #158,它建议安装 exec-path-from-shell。我从 MELPA 安装它并添加了这些行

(when (memq window-system '(mac ns))
  (exec-path-from-shell-initialize))

遵循说明。

使用上述行重新启动 Emacs 时出现错误:

Symbol's function definition is void: exec-path-from-shell-initialize

所以我在 exec-path-from-shell development 下查找了 Autoload issue #3(可以在 emacs-jedi issue #177 的链接中找到此链接)。按照其中一种解决方案,我重新启动了计算机,卸载并重新安装了 exec-path-from-shell,它神奇地解决了重新启动之前存在的问题。

现在我检查了emacs是否可以使用找到virtualenv

M-! which virtualenv

它给出了正确的位置。

然后我跑了:

M-x jedi:install-server 

现在似乎运行没有问题。第一次,有关于在下设置默认虚拟环境的消息

/Users/XXX/.emacs.d/.python-environments

除了

Running: pip install --upgrade /Users/XXX/.emacs.d/elpa/jedi-20140321.1323/...Done

但在随后的试验中,只显示了 pip 升级消息。

看到服务器安装没有问题,我关闭并重新启动 Emacs 并打开了一个 python 脚本文件。当我开始编辑时,我在 minibuffers 中收到了这些消息:

Error (jedi): Failed to start Jedi EPC server.
*** You may need to run "M-x jedi:install-server". ***
This could solve the problem especially if you haven't run the command yet
since Jedi.el installation or update and if the server complains about
Python module imports.

auto-complete error: (error Server may raise an error. Use "M-x epc:pop-to-last-server-process-buffer RET" to see full traceback:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file '/Users/XXX/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py': [Errno 2] No such file or directory`
)

因此,我意识到我必须发出命令:

M-x jedi:install-server 

每次我在打开任何 python 文件之前启动 Emacs。然后我终于能够看到在编辑过程中可以使用的自动完成功能。

虽然我每次都可以手动运行上述命令,但我想在启动 Emacs 时从我的 .emacs 中自动执行它。原来我的 .emacs 中有以下行

(setq jedi:server-command (list "python" "/Users/XXX/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py"))

在我的 .emacs 中删除这一行后,问题就消失了,jedi 现在可以正常工作了。

于 2014-09-23T23:33:18.883 回答
1

Marmalade 当前包含jedi版本 0.1.2,但您正在查看版本 0.2.0alpha2的文档。

0.1.2的文档有不同的说明

package.el(果酱或 MELPA)

您可以使用MarmaladeMELPA的package.el 界面安装 Jedi.el。由于 package.el 不支持安装非 elisp 包,您需要手动安装 Python 部分(请参阅下一节)。

然后在下一节中,重要的一点:

通过以下方式安装Jedipython-epc

  • make requirements(不需要root权限)或
  • pip install -r requirements.txt如果您想确定在哪里安装 Python 模块。您需要 root 权限(即sudo)才能将其安装在系统目录中。

您应该可以make requirements~/.emacs.d/elpa/jedi-0.1.2/目录中进行操作,但是类似的东西也pip install epc jedi应该可以。

于 2014-09-22T01:14:08.477 回答