emacs-jedi does not find numpy completions
Asked Answered
E

2

9

I installed emacs-jedi to get some code completion for python in emacs. In general, I must say that I am very impressed! It works well out of the box and finds completions quickly for built -in libraries. However, I use python for scientific purposes and rely on numpy and scipy for my work. For some reason, I get no completions for these modules.

Example:

import numpy 

testVector = numpy.array([1,2,3])

now typing testVector. and waiting, nothing shows up

Enneahedron answered 5/2, 2013 at 13:16 Comment(0)
C
6

I wonder why it does not work. It looks like sys.path problem but it should work without any configuration. But here is some idea for a brute force fix.

(1) Run the following script to get load path for numpy.

import os
import numpy
print(os.path.dirname(os.path.dirname(numpy.__file__)))

(2) Set jedi:server-args like this to forcefully add the path.

(setq jedi:server-args
      '("--sys-path" "THE/PRINTED/PATH/FOR/NUMPY"
        "--sys-path" "THE/PRINTED/PATH/FOR/SCIPY"))

See also: http://tkf.github.com/emacs-jedi/#jedi:server-args


Edit 1

Reading your comment on @syohex's answer, it looks like you mixed up some installation methods. jeid.el uses the virtualenv "env/" in the directory in which you have jedi.el, if it exists. el-get automatically creates "env/" if you have virtualenv. So, if you like system installation, you need to tell Jedi.el to ignore "evn/" by doing this:

(require 'jedi)
(setq jedi:server-command (list "python" jedi:server-script))

See also: http://tkf.github.com/emacs-jedi/#jedi:server-command


Edit 2

I have no clue why is that happening from your description. Here are several ways to narrow down the problem.

  1. Run make tryout in the directory in which jedi.el is installed (like ~/.emacs.d/el-get/jedi/).

    This opens a clean (i.e., it does not read your setup) Emacs process with minimal setup for jedi.el. Let's see if you can complete numpy and scipy.

  2. Can you import numpy and scipy in Emacs? You could have different environment variable in Emacs and shell. Run M-! python -c 'import numpy' RET. If this does not give you an error, then it is fine.

  3. Can you import numpy and scipy using env/bin/python? The best way to do it is to check it from Emacs.

    So first go to the directory in which jedi.el is installed (e.g., C-x C-f ~/.emacs.d/el-get/jedi/ RET).

    Then run M-! env/bin/python -c 'import numpy' RET. If this does not give you an error, then it should be possible to import numpy and scipy.

I hope at least one of them gives you an error, otherwise I need to think about another possibility.

Comradery answered 6/2, 2013 at 0:37 Comment(6)
I only manage to do this after starting jedi since jedi:server-command is void before that, so is jedi:server-script. I tried putting it in a python-mode hook so that it would only be run after jedi:setup, but keep getting void variable errors. I dont think I mixed up any installation methods - I followed the instructions for installation with el-get precisely.Enneahedron
Clrification: I tried first to force the inclusion of the numpy path as described. That did not change anything, still no completion.Enneahedron
Just call (require 'jedi) before using jedi:server-script. You can call it in python-mode-hook if you like.Comradery
I tried all of these options with the following results: 1. returns error message: mkdir -p elpa EL4T_EMACS=emacs EMACS=tools/el4t/emacs.sh carton install 2> elpa/install.log make: *** [elpa] Error 127 the elpa/install.log reads: /bin/sh: 1: carton: not found 2. works fine 3. does not find numpyEnneahedron
OK, so I guess VIRTUALENV_SYSTEM_SITE_PACKAGES=true make clean requirements should fix your problem. If it works for you, I will make this default.Comradery
I think that is a good idea. It turns out, on my system that is not enough though, since a combination of apt-get and pip for installing python packages have dispersed my python libraries all over the place..(/usr/lib/pymodules/python2.7, dist- and site packages in both /usr/lib/python2.7 and /usr/local/lib/python2.7 etc). I found a solution by activating jedi's virtualenv and using the virtualenvwrapper command add2virtualenv to add all the paths I needed to jedi's virtualenv. I now have completion working for all libraries on the paths that I added to the virtualenv.Enneahedron
C
1

I can get completion such case. Like following

enter image description here

You may use old requirement modules(jedi, epc, argparse). You should update them and try again.

Chronicle answered 5/2, 2013 at 14:38 Comment(2)
Even though epc and jedi where automatically installed by el-get when I installed emacs-jedi, I did a git pull in those folders just to be sure that I had the latest version. I also did sudo pip install argparse --upgrade which told me I already have the latest version of argparse. So the dependencies seem up to date, but I still do not get completion for numpy or scpipy.Enneahedron
Hmm, I use epc 0.0.3 and jedi 0.5b5. Please check your epc, jedi version.Chronicle

© 2022 - 2024 — McMap. All rights reserved.