Installing python server for emacs-jedi

2024/11/16 11:45:59

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 mainjedi_epc_server(**vars(ns))File "/Users/t_nithyanandan/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py", line 210, in jedi_epc_serverimport_jedi()File "/Users/t_nithyanandan/.emacs.d/elpa/jedi-0.1.2/jediepcserver.py", line 249, in import_jediimport 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.

Answer

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.

https://en.xdnf.cn/q/71352.html

Related Q&A

Multi-feature causal CNN - Keras implementation

Im currently using a basic LSTM to make regression predictions and I would like to implement a causal CNN as it should be computationally more efficient.Im struggling to figure out how to reshape my cu…

Adding a join to an SQL Alchemy expression that already has a select_from()

Note: this is a question about SQL Alchemys expression language not the ORMSQL Alchemy is fine for adding WHERE or HAVING clauses to an existing query:q = select([bmt_gene.c.id]).select_from(bmt_gene) …

How should I move blobs from BlobStore over to Google Cloud Storage?

Our application has been running on App Engine using the Blobstore for years. We would like to move our video files over to Google Cloud Storage. What is the best practice for migrating large blobs f…

Python: Find `sys.argv` before the `sys` module is loaded

I want to find the command line arguments that my program was called with, i.e. sys.argv, but I want to do that before Python makes sys.argv available. This is because Im running code in usercustomize.…

Dotted lines instead of a missing value in matplotlib

I have an array of some data, where some of the values are missingy = np.array([np.NAN, 45, 23, np.NAN, 5, 14, 22, np.NAN, np.NAN, 18, 23])When I plot it, I have these NANs missing (which is expected)f…

How to change the creation date of file using python on a mac?

I need to update the creation time of a .mp4 file so that it will appear at the top of a list of media files sorted by creation date. I am able to easily update both the accessed and modified date of …

Classification tree in sklearn giving inconsistent answers

I am using a classification tree from sklearn and when I have the the model train twice using the same data, and predict with the same test data, I am getting different results. I tried reproducing on…

Modifying binary file with Python

i am trying to patch a hex file. i have two patch files (hex) named "patch 1" and "patch 2"the file to be patched is a 16 MB file named "file.bin".i have tried many differ…

python error : module object has no attribute AF_UNIX

this is my python code :if __name__ == __main__: import socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect((0.0.0.0, 4000)) import time time.sleep(2) #sock.send(1)print …

How to speed up pandas string function?

I am using the pandas vectorized str.split() method to extract the first element returned from a split on "~". I also have also tried using df.apply() with a lambda and str.split() to produc…