Installing python server for emacs-jedi

落花浮王杯 提交于 2019-12-05 11:22:55

I managed to fix the problem thanks to help from Chris and syohex from emacs-jedi github. Credit goes to them in tracing this to Jedi version.

I am just linking the discussion on emacs-jedi issue #177 and pasting the workaround I found including other problems I encountered along the way.

I was using the Marmalade version which installs a much older version. So I uninstalled jedi and associated dependencies. I set my repository to MELPA and installed a much more recent version of jedi. This made the command

M-x jedi:install-server 

available which wasn't the case earlier.

However, issuing that command gave an error

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

I made sure I added the location of virtualenv to PATH in my .bashrc. So I looked up emacs-jedi issue #158 which suggests installing exec-path-from-shell. I installed it from MELPA and added the lines

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

following instructions.

Restarting Emacs with the above lines gave an error:

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

So I looked up Autoload issue #3 under exec-path-from-shell development (the link to this can be found in the link for emacs-jedi issue #177). Following one of the solutions, I restarted my computer, uninstalled and reinstalled exec-path-from-shell which magically did solve the problem that existed before the reboot.

Now I checked in emacs if virtualenv could be found using

M-! which virtualenv

It gave the right location.

Then I ran:

M-x jedi:install-server 

which now seemed to run without trouble. The first time, there were messages about setting up a default virtual environment under

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

besides

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

but in subsequent trials only the pip upgrade message was displayed.

Having seen that the server installed without trouble, I closed and restarted Emacs and opened a python script file. When I started editing, I got these messages in the 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.

and

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`
)

Thus, I realized that I have to issue the command:

M-x jedi:install-server 

every time I start Emacs before opening any python file. Then I was finally able to see the auto-completion features being available during editing.

Though I can run the above command every time manually, I wanted to automate it from my .emacs whenever Emacs is launched. It turned out that I had the following line in my .emacs

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

Upon removing this line in my .emacs, the problem went away and jedi is functional now.

Marmalade currently contains jedi version 0.1.2, but you're looking at documentation for version 0.2.0alpha2.

The documentation for 0.1.2 has different instructions:

package.el (Marmalade or MELPA)

You can install Jedi.el using package.el interface from Marmalade or MELPA. As package.el does not support installing non-elisp packages, you need to install Python part manually (see the next section).

And then in that next section, the imporant bit:

Install Jedi and python-epc by

  • make requirements (no need for root privileges) or
  • pip install -r requirements.txt if you want to determine where to install Python modules. You need root privileges (i.e., sudo) to install it in system directory.

You should be able to do make requirements from the ~/.emacs.d/elpa/jedi-0.1.2/ directory, but something like pip install epc jedi should work too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!