【问题标题】:vim - Youcomplete me unable to find an appropriate Python libraryvim - 你让我找不到合适的 Python 库
【发布时间】:2016-09-13 15:54:45
【问题描述】:

我已按照此处https://github.com/Valloric/YouCompleteMe 的说明进行操作 并且都安装了:

Cmake sudo apt-get install build-essential cmake

和 Python 标头 sudo apt-get install python-dev python3-dev

然后我cd ~/.vim/bundle/YouCompleteMe 并运行: ./install.py --clang-completer我得到了:

Searching Python 2.7 libraries... ERROR: unable to find an appropriate Python library.

然后我尝试了 python3 install.py --clang-completer 但还是得到了:

Searching Python 3.4 libraries... ERROR: unable to find an appropriate Python library.

有人知道发生了什么吗? 谢谢

【问题讨论】:

    标签: python vim cmake clang youcompleteme


    【解决方案1】:

    脚本未找到您的 python 库的路径。在执行以下操作之前,您可能需要确保已安装 setuptools:

    您看到的错误可能是由 ~/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py 中第 149 行的函数 FindPythonLibrariesOnLinux() 返回的

    您可以通过创建一个名为 youcompletemetest.py 的文件并用以下代码填充它,只运行导致您出现问题的脚本部分:

    import sys
    import os.path as p
    import subprocess
    import re
    
    NO_PYTHON_LIBRARY_ERROR = 'ERROR: unable to find an appropriate Python library.'
    PY_MAJOR, PY_MINOR = sys.version_info[ 0 : 2 ]
    LIBRARY_LDCONFIG_REGEX = re.compile(
    '(?P<library>\S+) \(.*\) => (?P<path>\S+)' )
    
    if not ( ( PY_MAJOR == 2 and PY_MINOR >= 6 ) or
                ( PY_MAJOR == 3 and PY_MINOR >= 3 ) or
                PY_MAJOR > 3 ):
        sys.exit( 'ycmd requires Python >= 2.6 or >= 3.3; '
                'your version of Python is ' + sys.version )
    
    def GetPythonNameOnUnix():
        python_name = 'python' + str( PY_MAJOR ) + '.' + str( PY_MINOR )
        # Python 3 has an 'm' suffix on Unix platforms, for instance libpython3.3m.so.
        if PY_MAJOR == 3:
            python_name += 'm' 
        return python_name
    
    
    def GetStandardPythonLocationsOnUnix( prefix, name ): 
        return ( '{0}/lib/lib{1}'.format( prefix, name ),
                '{0}/include/{1}'.format( prefix, name ) )
    
    
    def CheckOutput( *popen_args, **kwargs ):
        process = subprocess.Popen( stdout=subprocess.PIPE, *popen_args, **kwargs )
        output, unused_err = process.communicate()
        retcode = process.poll()
        if retcode:
            command = kwargs.get( 'args' )
            if command is None:
                command = popen_args[ 0 ]
            error = subprocess.CalledProcessError( retcode, command )
            error.output = output
            raise error
        return output
    
    
    def FindPythonLibrariesOnLinux():
        python_name = GetPythonNameOnUnix()
        python_library_root, python_include = GetStandardPythonLocationsOnUnix(
            sys.exec_prefix, python_name )
    
        python_library = python_library_root + '.so'
        if p.isfile( python_library ):
            return python_library, python_include
    
        python_library = python_library_root + '.a'
        if p.isfile( python_library ):
            sys.exit( NO_DYNAMIC_PYTHON_ERROR.format( library = python_library,
                                                    flag = '--enable-shared' ) )
    
        # On some distributions (Ubuntu for instance), the Python system library is
        # not installed in its default path: /usr/lib. We use the ldconfig tool to
        # find it.
        python_library = 'lib' + python_name + '.so'
        ldconfig_output = CheckOutput( [ 'ldconfig', '-p' ] ).strip().decode( 'utf8' )
        for line in ldconfig_output.splitlines():
            match = LIBRARY_LDCONFIG_REGEX.search( line )
            if match and match.group( 'library' ) == python_library:
                return match.group( 'path' ), python_include
    
        sys.exit( NO_PYTHON_LIBRARY_ERROR )
    
    print "\n".join(FindPythonLibrariesOnLinux());
    

    您可以使用以下命令运行该文件:

    python youcompletemetest.py 
    

    对我来说会输出

    /usr/lib/x86_64-linux-gnu/libpython2.7.so

    /usr/include/python2.7

    但对你来说,它无法找到 python。如果您知道 python 的安装位置,您可以找到该路径并将名为 FindPythonLibrariesOnLinux() 的函数的全部内容替换为包含 python 库位置的数组。

    所以打开源文件:

    vi ~/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py
    

    查找不起作用的功能: /^def\sFindPythonLibrariesOnLinux

    更改该函数,使其仅返回您的 python 库的完整路径(在我的情况下为以下):

    def FindPythonLibrariesOnLinux():
        return ["/usr/lib/x86_64-linux-gnu/libpython2.7.so","/usr/include/python2.7"]
    

    现在您可以继续安装了:

    ./install.py --clang-completer
    

    【讨论】:

      【解决方案2】:

      cygwin 上启用 YouCompleteMe 时,在为 python 3.4 安装 python-devel 包后,只有静态链接 (*.a) 版本的库可用:libpython3.4.dll.a .

      所以我修改了:

      ~/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py
      

      与:

      def FindPythonLibrariesOnLinux():
        return ["/usr/lib/libpython3.4.dll.a","/usr/include/python3.4"]
      

      我正在使用:(CYGWIN_NT-10.0 2.7.0(0.306/5/3) 2017-02-12 13:18 x86_64 Cygwin)

      【讨论】:

        【解决方案3】:

        也许这对你有帮助 => Issue #2162

          sudo apt install python-dev
        

        【讨论】:

          【解决方案4】:

          如果您从 Python.org 安装 Windows Python3 版本并将路径(例如,Windows Python 的c:/Program Files/ 路径)添加到 MSYS2/Cygwin 环境路径本地版本 Python 之前,则构建脚本无需修改或卸载本地 Python 即可运行。

          基本上,构建脚本似乎需要 Python 的典型 Windows 安装,因为它正在对布局做出一些假设?

          除了 CMake 使用 Visual Studio 工具并且它们在 Windows 环境级别运行并期望典型的 Windows Python 目录结构之外,我不确定为什么这种方法有效。 Python 的 MSYS2 目录结构与典型的 Windows Python 安装有很大不同。

          然后,您可以在构建完成后从 MSYS2 路径中删除 Windows Python 安装路径。

          【讨论】:

          • 应该添加,然后在调用build/install时不要使用python3,即使用“python install.py -all”来调用windows python
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2010-09-11
          • 2020-05-24
          • 2020-05-13
          • 2011-11-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多