Difficulty with python while installing YouCompleteMe in vim

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.