Skip to content
Advertisement

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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement