简体   繁体   English

Ubuntu 14.04上的Vim使用了一个有趣的python路径,python无法在其他模块中导入_io

[英]Vim on Ubuntu 14.04 uses a funny python path, python can't import _io among other modules

All of a sudden (probably after a package update or something) vim stopped working with YouCompleteMe and throws: 突然(可能是在更新软件包之后)vim停止使用YouCompleteMe并抛出:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: No module named _io

(this also happens when I try to import io from inside vim using :python import io ). (当我尝试使用:python import io从vim内部导入io时也会发生这种情况:python import io )。

I've been battling this for the last couple of hours, no idea what the problem is, reinstalled python and vim several times, both from source and from aptitude, no difference. 我在过去几个小时里一直在争夺这个问题,不知道问题是什么,重新安装python和vim几次,无论是来源还是来自aptitude都没有区别。 I've noticed that python inside vim uses a funny path compared to from the command line: 我注意到,与命令行相比,vim中的python使用了一个有趣的路径:

~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; print sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
>>> 

And from vim: 从vim:

:python import sys; print sys.path
['/usr/lib/python27.zip', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '
/usr/lib/python2.7/lib-dynload', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-pa
ckages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode', '_vim_path_']

I am not using virtualenv (I've noticed some people running into this with virtualenv set up). 我没有使用virtualenv (我注意到有些人在使用virtualenv设置时遇到了这个问题)。

Also must point out that Python works perfectly fine from the command line and I can happily import io when launching the interpreter and that this happens with both vim 8 compiled from source and vim-nox from aptitude. 还必须指出Python在命令行中运行得非常好,我可以在启动解释器时愉快地导入io ,并且这种情况发生在从源代码编译的vim 8和aptitude的vim-nox中。

Is it an issue with how python sees its path inside vim? 这是python如何在vim中看到它的path的问题? I'm at my wits' end, no idea what to do to fix this. 我在我的智慧结束,不知道如何解决这个问题。

YouCompleteMe provides an option g:ycm_server_python_interpreter to set a specific interpreter. YouCompleteMe提供了一个选项g:ycm_server_python_interpreter来设置特定的解释器。

Just add let g:ycm_server_python_interpreter = path/to/your/interpreter in your .vimrc with the path of your favored interpreter. 只需在.vimrc添加let g:ycm_server_python_interpreter = path/to/your/interpreter ,并使用您喜欢的解释器的路径。

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

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