我正在尝试按照此处的说明使用果酱包管理器为 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)时,我看到以下内容自动出现在迷你缓冲区中:
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,但这些方法似乎还没有走到这一步。我看到可用的绝地命令比上面列出的还要少。
有人可以帮我指出我遗漏了什么吗?
谢谢。
编辑:我想使用 Jedi 的主要目的是使用 python 编程的自动完成功能,尽管我相信 Jedi 有许多强大的功能。出于这样的目的,python 服务器是必不可少的还是可以解决它?最后,当然,我想利用 Jedi 中的更多功能。
最佳答案
感谢来自 emacs-jedi github 的 Chris 和 syohex 的帮助,我设法解决了这个问题。他们将此追溯到 Jedi 版本,这归功于他们。
我只是链接关于 emacs-jedi issue #177 的讨论并粘贴我发现的解决方法,包括我在此过程中遇到的其他问题。
我使用的是 Marmalade 版本,它安装了一个更旧的版本。所以我卸载了 jedi 和相关的依赖项。我将我的存储库设置为 MELPA 并安装了更新版本的绝地武士。这使得命令
M-x jedi:install-server
可用,以前不是这样。
但是,发出该命令会出错
python-environment--make-with-runner: Program named "virtualenv" does not exist.
我确保将 virtualenv 的位置添加到我的 .bashrc 中的 PATH。 所以我查了一下emacs-jedi issue #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 开发下查找了 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 脚本文件。当我开始编辑时,我在迷你缓冲区中收到了这些消息:
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 现在可以正常工作了。
关于python - 为 emacs-jedi 安装 python 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25963476/