As part of my ongoing evolution of my server create scripting, I’m adding YouCompleteMe to the mix. Code completion is a really nice thing to have and YCM does it very well.
This is a more complicated plugin to install as it depends on a language server so it can work asynchronously and must be compiled when installed. The first thing is to ensure that the prerequisites are installed:
rob@ub01:~$ sudo apt-get install cmake llvm
After that, edit the .vimrc file so that the plugin is added to vim-plug and add a little extra time for the timeout as the installation procedure takes a few seconds. The following lines do the trick:
let g:plug_timeout = 300 " Increase vim-plug timeout for YouCompleteMe.
Plug 'ycm-core/YouCompleteMe', { 'do': './install.py' }
Then, restart Vim and run :PlugInstall. This runs the installer and compiles the server. Easy-peasy.
Except when it doesn’t work. The first time I tried this, I got the following error:
Searching Python 3.8 libraries...
ERROR: found static Python library (/home/rob/.pyenv/versions/3.8.2/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a) but a dynamic one is required. You must use a Python compiled with the --enable-shared flag. If using pyenv, you need to run the command:
export PYTHON_CONFIGURE_OPTS="--enable-shared"
before installing a Python version.
I can deal with errors that have a nice clean error message like this. Since I am using pyenv, this told me exactly what to do and I fixed the issue with:
rob@ub01:~$ export PYTHON_CONFIGURE_OPTS="--enable-shared"
rob@ub01:~$ pyenv install 3.8.2
I was already using Python 3.8.2 and this installed it again with the –enable-shared flag set.
After that was done, it was smooth sailing and the plugin works. I’ll do some more configuration to it and update my scripts so that this can be done on new VMs that I create.