使用Jedi-vim自动完成错误

时间:2016-07-31 13:45:05

标签: python vim vim-plugin jedi-vim

-- Omni completion (^O^N^P) Pattern not found

这是我在查看Vim中的消息时遇到的错误。

Please install Jedi if you want to use jedi-vim.
The error was: dlopen(/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder^@  Referenced fro
m: /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so^@  Expected in: flat namespace^@ in /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework
/Versions/2.7/lib/python2.7/lib-dynload/_io.so

Press ENTER or type command to continue

但我已经使用pip安装了Jedi

$ pip freeze
jedi==0.9.0
vboxapi==1.0 

我试图从vim运行:python import jedi;,它会出现以下错误:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/jedi/__init__.py", line 41, in <module>
    from jedi.api import Script, Interpreter, NotFoundError, set_debug_function
  File "/usr/local/lib/python2.7/site-packages/jedi/api/__init__.py", line 16, in <module>
    from jedi.parser import Parser, load_grammar
  File "/usr/local/lib/python2.7/site-packages/jedi/parser/__init__.py", line 22, in <module>
    from jedi.parser import tokenize
  File "/usr/local/lib/python2.7/site-packages/jedi/parser/tokenize.py", line 16, in <module>
    from io import StringIO
  File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
  Referenced from: /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

我的命令行中的Python显示以下版本

>>> import sys
>>> sys.version
'2.7.12 (default, Jun 29 2016, 14:05:02) \n[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]'
>>>

但是如果运行以下命令来自Vim

:python import sys; print sys.version

输出

2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]

现在我如何更新vim正在使用的python? /这里究竟发生了什么,我该怎么做才能解决它?

4 个答案:

答案 0 :(得分:1)

这是因为Mac上安装了2个版本的python。 默认情况下出现的是/ usr / bin目录,是2.7.10版本。我使用brew安装的一个是在/ usr / local / bin目录下,是2.7.12版本。

Vim正在使用2.7.10版本,但在brew安装包的文件夹中查找包。 所以我做了一个brew卸载python,一切正常。

(但我丢失了pip,所有的软件包都是通过pip安装的。我应该更加小心)

答案 1 :(得分:0)

我用病原体安装了jedi-vim,现在可以了。

pip install --user jedi
cd ~/.vim/bundle/
git clone https://github.com/davidhalter/jedi-vim.git

您还可以运行

sudo apt-get install vim-python-jedi

这应该有帮助

答案 2 :(得分:0)

在我的情况下,卸载不是解决方案,vim在一开始就抱怨,那是找不到python的支持 我做了以下事情:

cd /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/

mv _io.so _io.so.orig
cp /usr/lib/python2.7/lib-dynload/_io.so ./

(我已经从源代码构建了vim8 - 来自github.com/vim/vim.git)

./configure --enable-pythoninterp --with-python-config-dir=/usr/lib/python2.7/config/

make

sudo make install)

答案 3 :(得分:0)

至少对于Ubuntu 16.04,这是因为默认的Vim包是针对Python 3.5编译的。要修复此错误,除了相关的Jedi包之外,您还需要安装有关Vim和安装以下软件包的任何内容:

sudo apt-get install vim-addon-manager vim-common vim-gnome-py2 \
vim-gtk3-py2 vim-gui-common vim-nox-py2 vim-python-jedi vim-runtime