为emacs-jedi安装python服务器

Nit*_*hya 5 python emacs python-2.7 emacs-jedi

我正在尝试使用marmalade包管理器按照以下说明安装Jedi for emacs - http://tkf.github.io/emacs-jedi/latest/.包管理器安装Jedi及其依赖项.但我不能使用以下命令安装python服务器:

M-x jedi:install-server
Run Code Online (Sandbox Code Playgroud)

因为即使在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
Run Code Online (Sandbox Code Playgroud)

我的.emacs有以下内容:

(autoload 'jedi:setup "jedi" nil t)
(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:complete-on-dot t)
Run Code Online (Sandbox Code Playgroud)

我在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
)
Run Code Online (Sandbox Code Playgroud)

我尝试使用其他方法安装jedi,例如el-get和手动但是那些似乎甚至没有走到这一步.我看到可用的jedi命令甚至比上面列出的要少.

有人可以帮助指出我缺少的东西吗?

谢谢.

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

Nit*_*hya 8

感谢Chris和来自emacs-jedi github的syohex的帮助,我设法解决了这个问题.在追溯到Jedi版本时,他们可以获得信用.

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

我使用的Marmalade版本安装了更旧的版本.所以我卸载了jedi和相关的依赖项.我将我的存储库设置为MELPA并安装了更新版本的jedi.这发了命令

M-x jedi:install-server 
Run Code Online (Sandbox Code Playgroud)

虽然早先不是这样的.

但是,发出该命令会出错

python-environment--make-with-runner: Program named "virtualenv" does not exist.
Run Code Online (Sandbox Code Playgroud)

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

(when (memq window-system '(mac ns))
  (exec-path-from-shell-initialize))
Run Code Online (Sandbox Code Playgroud)

以下说明.

使用上面的行重新启动Emacs会出错:

Symbol's function definition is void: exec-path-from-shell-initialize
Run Code Online (Sandbox Code Playgroud)

所以我在exec-path-from-shell开发下查找了Autoload问题#3(可以在emacs-jedi问题#177的链接中找到这个链接).根据其中一个解决方案,我重新启动了我的计算机,卸载并重新安装了exec-path-from-shell,它神奇地解决了重启之前存在的问题.

现在我检查了emacs,如果可以找到virtualenv使用

M-! which virtualenv
Run Code Online (Sandbox Code Playgroud)

它给了正确的位置.

然后我跑了:

M-x jedi:install-server 
Run Code Online (Sandbox Code Playgroud)

现在似乎没有遇到麻烦.第一次,有关于设置默认虚拟环境的消息

/Users/XXX/.emacs.d/.python-environments
Run Code Online (Sandbox Code Playgroud)

除了

Running: pip install --upgrade /Users/XXX/.emacs.d/elpa/jedi-20140321.1323/...Done
Run Code Online (Sandbox Code Playgroud)

但在后续试验中,仅显示了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.
Run Code Online (Sandbox Code Playgroud)

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`
)
Run Code Online (Sandbox Code Playgroud)

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

M-x jedi:install-server 
Run Code Online (Sandbox Code Playgroud)

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

虽然我每次都可以手动运行上面的命令,但是每当启动Emacs时我都想从我的.emacs中自动执行它.事实证明,我的.emacs中有以下行

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

在.emacs中删除此行后,问题就消失了,jedi现在正在运行.