将vim/youcompleteme与anaconda python集成

8
我正在尝试获取 Vim 插件 YouCompleteMe,但在安装了 Anaconda Python 发行版之后,它就无法工作了。
相关信息:
Vim 中的 :YcmDebugInfo 返回 'E858: Eval Did not return a valid Python object.'
在我的 vimrc 文件中,我有以下内容:
Bundle 'Valloric/YouCompleteMe'
let g:ycm_auto_trigger = 1
let g:ycm_path_to_python_interpreter = '/Users/briantoomey/anaconda/bin/python'
let g:ycm_filetype_blacklist = {}

在 GitHub 上查看了其他人的 vimrc 后,我也尝试了。
let g:ycm_path_to_python_interpreter = '/usr/bin/python'
let g:ycm_path_to_python_interpreter = '/usr/bin/python2'

在vim中返回的错误都与此相关。
youcompleteme#Enable

在bash中,
$ which python

产量,产出。
$ /Users/briantoomey/anaconda/bin/python

and $ python --version

yields

$ Python 2.7.6 :: Anaconda 1.9.0 (x86_64)

任何想法?

我认为问题在于你的vim构建版本链接的Python可能与你的Anaconda安装版本不同。看起来你在使用Mac电脑。如果你正在使用MacVim,可以执行以下命令:"otool -L /Applications/MacVim.app/Contents/MacOS/Vim"并查看它链接的Python版本。这只是一个猜测,因为我不知道YCM扩展是如何工作的;它可能完全独立于vim内置的Python支持。你也可以查看:http://bit.ly/1mGBQZ6 - Peter Wang
1
如果您能够重现这是与Anaconda相关的问题,而不是您特定的系统设置,为什么不在YouCompleteMe的问题跟踪器中打开一个问题呢?! - Ingo Karkat
1
我在让这个工作时也遇到了类似的问题(尽管是不同的错误),Python sys.executable与sys.version不匹配(当使用:python调用时),一个指向系统,一个指向Anaconda。我已经让它们都指向系统,使其正常工作(虽然这不是我想要的!)。你解决了这个问题吗? - Andy Hayden
3个回答

2
我和 @Andy_Haden 处于同样的情况,我在 github 的第8个问题(https://github.com/Valloric/YouCompleteMe/issues/8)中看到了 chrischoy 的评论:
""" 对于 Anaconda 用户,
只需在编译 YCM 时暂时将 /path/to/anaconda/bin/python-config 中的 python-config 文件更改为 python-config.tmp,然后重新命名即可解决问题。 """

1

操作系统: Redhat 7

错误: YouCompleteMe不可用: 需要使用支持Python (2.7.1+ 或 3.4+)的编译的Vim

必须取消激活所需的conda环境。

rm -rf ~/.vim ~/vim #start fresh if needed
git clone https://github.com/vim/vim.git
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
cd vim/src

退出 Conda 环境 conda deactivate (如果需要退出基础环境,则多次执行)

注意:将 "full path to" 更改为 Conda 安装的完整路径。在配置之前,使用 ls 测试路径是否正确。

./configure --disable-nls --enable-cscope --enable-gui=no --enable-multibyte --enable-pythoninterp --enable-rubyinterp --with-features=huge --with-python-config-dir=<full path to>/anaconda3/lib/python3.6/config-3.6m-x86_64-linux-gnu --with-tlib=ncurses --without-x
make
sudo make install

激活回到conda环境。 conda activate <我的环境> 将以下内容放入.vimrc文件中(包括NERDTree和flake8):
set nocompatible              " required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)

" ...

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

" Enable folding
set foldmethod=indent
set foldlevel=99

" Enable folding with the spacebar
nnoremap <space> za

Plugin 'tmhedberg/SimpylFold'

Plugin 'vim-scripts/indentpython.vim'

set encoding=utf-8

Bundle 'Valloric/YouCompleteMe'

let g:ycm_autoclose_preview_window_after_completion=1
map <leader>g  :YcmCompleter GoToDefinitionElseDeclaration<CR>

Plugin 'vim-syntastic/syntastic'

Plugin 'nvie/vim-flake8'

let python_highlight_all=1
syntax on

Plugin 'jnurmine/Zenburn'
Plugin 'altercation/vim-colors-solarized'

Plugin 'scrooloose/nerdtree'

Plugin 'jistr/vim-nerdtree-tabs'

let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree

安装:

vim #enter vim
:PluginInstall #at command prompt

cd ~/.vim/bundle/YouCompleteMe 
python3 ./install.py #youcompleteme requires an installation step

通过使用vim打开一个Python文件来测试安装


安装YouCompleteMe时,这些指令已在macOS 10.13和10.14上进行了测试。需要在conda环境中安装cmake,并使用conda install python -c conda-forge安装或更新Python。 - Stuber

0

我使用Anaconda,但使用conda-forge提供我的Python二进制文件。到目前为止,我已经能够在没有任何问题的情况下使用YouCompleteMe。要使用它,您只需要按照以下步骤操作,这也在他们的网站上列出。

conda config --add channels conda-forge 
conda install python

然后正常构建YouCompleteMe,它应该可以正常工作。我已经成功地在Python 3.6和3.7上完成了这个过程。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接