简体   繁体   English

如何在 VIM 中指定 Python 解释器版本?

[英]How to specify Python interpreter version in VIM?

In order to write C++ in Vim with plugin, Clang_complete.为了在 Vim 中用插件编写 C++,Clang_complete。
After installing, this error occurs:安装后出现这个错误:

Error detected while processing function <SNR>14_ClangCompleteInit..<SNR>14_initClangCompletePython:
clang_complete: No python support available.
Cannot use clang library
Compile vim with python support to use libclang

But my vim supports both python and python3.但是我的 vim 支持 python 和 python3。 +python/dyn +python3/dyn
then I check my python interpreter:然后我检查我的python解释器:

:echo has('python')      # output is 0
:echo has('python3')     # output is 1

So, I think the reason is my vim dynamic load python3 interpreter by default.所以,我认为原因是我的vim默认动态加载python3解释器。
Can I change python interpreter?我可以更改 python 解释器吗? or set default dynamic load version of python?或者设置python的默认动态加载版本?

You probably don't want to (or at least should not) set python3 as the default python interpreter for vim, as then some (most of) your plugins will become incompatible, such as YouCompleteMe and clang_complete itself, because they do not have python3 support.您可能不想(或至少不应该)将python3设置为 vim 的默认 Python 解释器,因为那样您的某些(大部分)插件将变得不兼容,例如YouCompleteMeclang_complete本身,因为它们没有python3支持。 Normally plugins that do support python3 let you decide if you want to use it by adding to your .vimrc通常支持python3插件让你决定是否要通过添加到.vimrc来使用它

let g:syntastic_python_python_exec = 'python3' 

Solution: the :echo has('python') showing 0 is actually telling you that vim is perhaps not compiled with python2 .解决方案: :echo has('python')显示0实际上是在告诉你 vim 可能不是用python2编译的。 So first check the output of vim --version and you should be able to see a list of shared libraries that your compiler has built vim against.因此,首先检查vim --version的输出,您应该能够看到编译器针对其构建 vim 的共享库列表。 Do you see the following?你看到以下内容了吗? (eg for python 2.7): (例如对于python 2.7):

-L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7

If not (or if you see both -lpython2.x and -lpython3.x I suggest you compile vim from source, linking it specifically to -lpython2.x . It is not that difficult to build vim from source. First make sure to remove all your current vim installation, for instance using aptitude you'd do:如果没有(或者如果您同时看到-lpython2.x-lpython3.x我建议您从源代码编译 vim,将其专门链接到-lpython2.x 。从源代码构建 vim 并不难。首先确保删除您当前的所有 vim 安装,例如使用aptitude您会这​​样做:

sudo apt-get remove --purge vim vim-runtime vim-gnome vim-tiny vim-common vim-gui-common

clone vim mercurial克隆 vim mercurial

hg clone https://code.google.com/p/vim/
cd vim

and then run ./configure with the following flags:然后使用以下标志运行./configure

 ./configure --with-features=huge \
        --enable-cscope \
        --enable-pythoninterp \
        --enable-largefile \
        --with-python-config-dir=/usr/lib/python2.7/config 

you might also want to link against ruby and lua if you want, and then finally run如果需要,您可能还想链接到rubylua ,然后最后运行

make build
make install

Here is shell script that will automate the whole process for you. 是 shell 脚本,它将为您自动化整个过程。 This might be a bit of an overkill, but I think this is how you should handle this to not run with compatibility issues with your future packages.这可能有点矫枉过正,但我​​认为这是您应该如何处理它,以免与您未来的软件包存在兼容性问题。

" .gvimrc

let &pythonthreedll='C:\...\python37.dll'
let &pythonthreehome='C:\...\Python37'

check:查看:

:py3 print('hello')

and VIM should be matched as the Python (I mean 64, 32 bit)和 VIM 应该与 Python 匹配(我的意思是 64、32 位)

windows vim x64 download windows vim x64 下载

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

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