Installing python server for emacs-jedi
Asked Answered
T

2

7

I am trying to install Jedi for emacs using marmalade package manager by following instructions here -- http://tkf.github.io/emacs-jedi/latest/. The package manger installs Jedi along with its dependencies. But I cannot install python server using:

M-x jedi:install-server

because that command is not available even after restarting emacs after jedi installation. The only available commands are:

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

My .emacs has the following:

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

I am using emacs on Mac OS X.

At this current state when I open any python file (I use python 2.7), I see the following appear automatically in the 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
)

I tried installing jedi using other methods such as el-get and also manually but those seem to not even go this far. I see that the jedi commands available are even lesser than listed above.

Could someone help point out what I am missing?

Thanks.

Edit: The primary purpose I would like to use Jedi is to use auto-completion features for python programming although I believe Jedi has many powerful features. For such a purpose, is the python server essential or could one work around it? Eventually, of course, I'd like to take advantage of many more features in Jedi.

Talesman answered 21/9, 2014 at 20:22 Comment(1)
I have posted my answer below that helped me solve this problem including other minor problems I faced along the way. @Chris, I couldn't upvote your answer because I don't have enough reputation points yet but thanks for pointing me in the right direction of fetching the right emacs-jedi version.Talesman
T
10

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.

Talesman answered 23/9, 2014 at 23:33 Comment(1)
I had exactly the same problem, however I did not have that line you removed. I fixed it by uninstalling jedi and epc using pip uninstall jedi and pip uninstall epc, and then installing them using pip install --user epc and pip install --user jedi.Outfall
P
1

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.

Positive answered 22/9, 2014 at 1:14 Comment(3)
I installed epc (0.0.5) and jedi (0.8.1-final0) using "sudo pip install epc jedi". I still get the same error. I am able to import jedi in ipython though.Talesman
@Talesman these modules must be installed into whatever Python environment you're using. So if, for instance, you're using a virtualenv, installing system wide probably won't help much. You may also need to use something like pyvenv in Emacs to make it use the proper virtualenv.Positive
I have virtualenv installed but I wasn't using after activating any specific virtual environment. So I meant to install it system wide. I think I have managed to fix the issue with the main problem being I hadn't installed the latest version. I will post my answer here.Talesman

© 2022 - 2024 — McMap. All rights reserved.