简体   繁体   English

emacs-jedi没有找到numpy完成

[英]emacs-jedi does not find numpy completions

I installed emacs-jedi to get some code completion for python in emacs. 我安装了emacs-jedi来为emacs中的python获取一些代码。 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. 但是,我将python用于科学目的,并依赖于numpy和scipy来完成我的工作。 For some reason, I get no completions for these modules. 出于某种原因,我没有完成这些模块的完成。

Example: 例:

import numpy 

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

now typing testVector. 现在输入testVector。 and waiting, nothing shows up 等待,没有任何表现

I wonder why it does not work. 我想知道为什么它不起作用。 It looks like sys.path problem but it should work without any configuration. 它看起来像sys.path问题,但它应该没有任何配置工作。 But here is some idea for a brute force fix. 但是这里有一个关于蛮力修复的想法。

(1) Run the following script to get load path for numpy. (1)运行以下脚本获取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. (2)设置jedi:server-args这样强制添加路径。

(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 另见: http//tkf.github.com/emacs-jedi/#jedi : server-args


Edit 1 编辑1

Reading your comment on @syohex's answer, it looks like you mixed up some installation methods. 阅读你对@ syohex的答案的评论,看起来你混淆了一些安装方法。 jeid.el uses the virtualenv "env/" in the directory in which you have jedi.el, if it exists. jeid.el在你有jedi.el的目录中使用virtualenv“env /”,如果它存在的话。 el-get automatically creates "env/" if you have virtualenv. 如果你有virtualenv,el-get会自动创建“env /”。 So, if you like system installation, you need to tell Jedi.el to ignore "evn/" by doing this: 所以,如果你喜欢系统安装,你需要通过这样做告诉Jedi.el忽略“evn /”:

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

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


Edit 2 编辑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/ ). 在安装jedi.el的目录中运行make tryout tryout(如~/.emacs.d/el-get/jedi/ )。

    This opens a clean (ie, it does not read your setup) Emacs process with minimal setup for jedi.el. 这将打开一个干净的(即,它不会读取您的设置)Emacs进程与jedi.el的最小设置。 Let's see if you can complete numpy and scipy. 让我们看看你是否可以完成numpy和scipy。

  2. Can you import numpy and scipy in Emacs ? 你能在Emacs中导入numpy和scipy吗? You could have different environment variable in Emacs and shell. 您可以在Emacs和shell中使用不同的环境变量。 Run M-! python -c 'import numpy' RET M-! python -c 'import numpy' RET M-! python -c 'import numpy' RET . 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 ? 你能用env/bin/python导入numpy和scipy吗? The best way to do it is to check it from Emacs. 最好的方法是从Emacs检查它。

    So first go to the directory in which jedi.el is installed (eg, Cx Cf ~/.emacs.d/el-get/jedi/ RET ). 所以首先转到安装jedi.el的目录(例如, Cx Cf ~/.emacs.d/el-get/jedi/ RET )。

    Then run M-! env/bin/python -c 'import numpy' RET 然后运行M-! env/bin/python -c 'import numpy' RET M-! env/bin/python -c 'import numpy' RET . 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. 如果这不会给你一个错误,那么应该可以导入numpy和scipy。

I hope at least one of them gives you an error, otherwise I need to think about another possibility. 我希望其中至少有一个能给你一个错误,否则我需要考虑另一种可能性。

I can get completion such case. 我可以完成这样的案件。 Like following 喜欢以下

在此输入图像描述

You may use old requirement modules(jedi, epc, argparse). 您可以使用旧的需求模块(jedi,epc,argparse)。 You should update them and try again. 您应该更新它们并再试一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM