Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difficulty with python while installing YouCompleteMe in vim

I've followed these instructions, in order to install YouCompleteMe in Vim, but when I issue:

./install.py --clang-completer

The following error message comes up:

Searching Python 2.7 libraries...
ERROR: found static Python library (/usr/local/lib/python2.7/config/libpython2.7.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.
Traceback (most recent call last):
  File "./install.py", line 44, in <module>
    Main()
  File "./install.py", line 33, in Main
    subprocess.check_call( [ python_binary, build_file ] + sys.argv[1:] )
  File "/usr/local/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/local/bin/python', u'/home/anmol/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py', '--clang-completer']' returned non-zero exit status 1

and now I'm stuck, what should I do?

like image 376
anmol porwal Avatar asked Oct 18 '16 12:10

anmol porwal


People also ask

How do I install Vim in Python?

You need to compile Vim yourself or get a prebuilt Vim package that was compiled with Python support. If you're on a Debian based system, the easiest way is to download the vim-gnome or vim-gtk package from apt(apt install vim-gtkfor instance). Other distros might have a similar package with python support built in.

How many versions of Vim does Python support?

Simplest way for a clean uninstall/install of vim with python support 25 Vim 8.0 Python support 0 Installing clang_complete Errors Related 1 How do I enable profile in vim? 5 Compiling vim from source just enabling clipboard 1 Enabling or installing blowfish2 capabilities on VIM 7.4.52 22 How can I install 64-bit Vim on Windows? 13

What version of Python does Vim-GTK install?

It seems that, these days, vim-gtk installs Python 3 (as one would hope!). I was confused when :echo has('python')was still returning 0, until I realised :echo has('python3')returned 1.

Does Anaconda need to compile Vim as well?

They might want to compile vim as well, especially if you want code-completion. Here is the configure command: Modified configure command for anaconda:


1 Answers

I checked YouCompleteMe's build system and it uses a custom build script that uses the Python module distutils to find the paths to Python's library and include directories. Your /usr/local/ installation of Python is probably included in your PATH variable before the official /usr installation so just running python probably runs your custom installation, making distutils return its directories.

To check whether this is true, try running which python. I assume it will return something like /usr/local/bin/python.

At this point, I see several options (in order of preference).

  1. Try running YCM's install script by specifying which Python executable should run it explicitly: /usr/bin/python ./install.py --clang-completer

    If you use any additional completers with YCM, you should add the appropriate flags to the above line (e.g. --js-completer for JavaScript completion).

  2. Edit the script third_party/ycmd/build.py in YouCompleteMe's plugin directory to hardcode the paths for your custom Python installation. For instance, you could replace the existing FindPythonLibraries function with the following:

    def FindPythonLibraries():
        return ('/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so',
                '/usr/include/python2.7')
    

    Note that this will make it harder to update YouCompleteMe since you'll have to ensure it doesn't get overwritten when you update its source.

  3. Replace your custom installation of Python with one built as a shared library. The details of this will depend on how you installed the existing Python installation in the first place. You can check whether you installed it through a package by using dpkg -S /usr/local/lib/python2.7/config/libpython2.7.a. This command will tell you which package installed that file, unless you installed it manually (bypassing the package manager).
  4. Remove your custom /usr/local Python installation while ensuring you have a Python from the official repositories installed (packages python2.7 and libpython2.7).

In the long run, you would probably be better off by using the official Python packages.

like image 184
dkasak Avatar answered Sep 30 '22 17:09

dkasak