ubuntu 18.04 安装youcompleteme教程和出现的问题

ubutu18.04  使用vim-plug 安装youcompleteme 自动补全插件:

环境(vmware 虚拟机,vim 8.0 python3 )

(1)安装 vim-plug 插件管理项,下载网址如下:https://github.com/junegunn/vim-plug

插件管理如下图:

Linux下使用下面命令:

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \

    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

然后在用户的根目录下找到.vimrc文件,若没有.vimrc 则使用 touch .vimrc 新建。

修改.vimrc文件

下面是vim-plug 给出的例子:

" Specify a directory for plugins

" - For Neovim: ~/.local/share/nvim/plugged

" - Avoid using standard Vim directory names like 'plugin'

call plug#begin('~/.vim/plugged')

 

" Make sure you use single quotes

 

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align

Plug 'junegunn/vim-easy-align'

 

" Any valid git URL is allowed

Plug 'https://github.com/junegunn/vim-github-dashboard.git'

 

" Multiple Plug commands can be written in a single line using | separators

Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

 

" On-demand loading

Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }

Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

 

" Using a non-master branch

Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

 

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)

Plug 'fatih/vim-go', { 'tag': '*' }

 

" Plugin options

Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }

 

" Plugin outside ~/.vim/plugged with post-update hook

Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }

 

" Unmanaged plugin (manually installed and updated)

Plug '~/my-prototype-plugin'

 

" Initialize plugin system

call plug#end()

修改好.vimrc 文件后,打开vim 进入命令行模式 输入PlugInstall 安装插件,安装过程如上图。

对于youcompleteme 插件由于插件比较大,有些子模块在国内没有vpn 的话是访问不到的,所以会出现cant     connect  port 443 。单独下载youcomplete 插件。

 

 

考虑到网速的限制我们修改git的配置:

git config http.postBuffer 524288000

git config --global http.lowSpeedLimit 0 

git config --global http.lowSpeedTime 999999

 

 

cd .vim/plugged/ 进入 plugged目录下执行   git  clone  https://github.com/ycm-core/YouCompleteMe.git

我当时执行的时候有网络速度的影响,会出现中断的错误,错误信息是文件还在下载端口就被关闭。

所以采用下列的下载方法:

git clone --depth=1  https://github.com/ycm-core/YouCompleteMe.git

 

 

Cloning into 'YouCompleteMe'...

remote: Enumerating objects: 116, done.

remote: Counting objects: 100% (116/116), done.

remote: Compressing objects: 100% (108/108), done.

remote: Total 116 (delta 9), reused 54 (delta 2), pack-reused 0

Receiving objects: 100% (116/116), 319.10 KiB | 397.00 KiB/s, done.

Resolving deltas: 100% (9/9), done.

 

然后进入:youcomplete 目录执行:git fetch --unshallow

remote: Enumerating objects: 34745, done.

remote: Counting objects: 100% (34745/34745), done.

remote: Compressing objects: 100% (20989/20989), done.

remote: Total 34682 (delta 12692), reused 34553 (delta 12563), pack-reused 0

Receiving objects: 100% (34682/34682), 31.86 MiB | 200.00 KiB/s, done.

Resolving deltas: 100% (12692/12692), completed with 53 local objects.

执行结束后递归的获取相应的子模块的:

git  submodule updata --init -recursive

执行的过程中会报下面的错误:

fatal: unable to access 'https://go.googlesource.com/tools/': Failed to connect to go.googlesource.com port 443: Connection refused

fatal: clone of 'https://go.googlesource.com/tools' into submodule path '/home/iwen/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x/tools' failed

Failed to clone 'third_party/go/src/golang.org/x/tools'. Retry scheduled

 

原因是国内不能访问 https://go.googlesource.com/tools 我们进入/home/iwen/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x/tools下将tools 删除,然后把需要的文件git clone下来:

git  clone  https://github.com/golang/tools.git

 

Cloning into 'tools'...

remote: Enumerating objects: 151, done.

remote: Counting objects: 100% (151/151), done.

remote: Compressing objects: 100% (116/116), done.

remote: Total 30584 (delta 65), reused 79 (delta 31), pack-reused 30433

Receiving objects: 100% (30584/30584), 14.27 MiB | 907.00 KiB/s, done.

Resolving deltas: 100% (21272/21272), done.

 

再次执行:git  submodule updata --init -recursive

等待执行完毕后进入 youcomplete 目录执行

Python run_tests.py 文件,主要是看文件和python3 是否缺少必要的模块

 

出现报错:CMake Error: The source directory "/home/iwen/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/cregex" does not appear to contain CMakeLists.txt.

Specify --help for usage, or press the help button on the CMake GUI.

ERROR: the build failed.

在这个目录下缺少CMakeLists.txt 文件,解决方法如下:

进入这个目录删除原来的creget 文件 然后重新初始化获取文件。

cd  /home/iwen/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/

 

rm  -rf  cregex/

 

git submodule update --init --recursive

 

执行完毕后,再次python3  run_tests.py 

 

报错 2:

/usr/bin/python3: No module named nose

Traceback (most recent call last):

  File "run_tests.py", line 100, in <module>

    Main()

  File "run_tests.py", line 96, in Main

    NoseTests( parsed_args, nosetests_args )

  File "run_tests.py", line 88, in NoseTests

    subprocess.check_call( [ sys.executable, '-m', 'nose' ] + nosetests_args )

  File "/usr/lib/python3.6/subprocess.py", line 311, in check_call

    raise CalledProcessError(retcode, cmd)

subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'nose', '-v', '--with-id', '/home/iwen/.vim/plugged/YouCompleteMe/python']' returned non-zero exit status 1

缺少nose 模块,安装nose模块:

 sudo pip3  install nose

 

再次 python3  run_tests.py

报错 3:

#1 Failure: ModuleNotFoundError (No module named 'future') ... ERROR

 

======================================================================

ERROR: Failure: ModuleNotFoundError (No module named 'future')

----------------------------------------------------------------------

Traceback (most recent call last):

  File "/usr/local/lib/python3.6/dist-packages/nose/failure.py", line 39, in runTest

    raise self.exc_val.with_traceback(self.tb)

  File "/usr/local/lib/python3.6/dist-packages/nose/loader.py", line 418, in loadTestsFromName

    addr.filename, addr.module)

  File "/usr/local/lib/python3.6/dist-packages/nose/importer.py", line 47, in importFromPath

    return self.importFromDir(dir_path, fqname)

  File "/usr/local/lib/python3.6/dist-packages/nose/importer.py", line 94, in importFromDir

    mod = load_module(part_fqname, fh, filename, desc)

  File "/usr/lib/python3.6/imp.py", line 245, in load_module

    return load_package(name, filename)

  File "/usr/lib/python3.6/imp.py", line 217, in load_package

    return _load(spec)

  File "<frozen importlib._bootstrap>", line 684, in _load

  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 678, in exec_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "/home/iwen/.vim/plugged/YouCompleteMe/python/ycm/tests/__init__.py", line 25, in <module>

    from ycm.tests.test_utils import MockVimModule

  File "/home/iwen/.vim/plugged/YouCompleteMe/python/ycm/tests/test_utils.py", line 26, in <module>

    from future.utils import iteritems, PY2

ModuleNotFoundError: No module named 'future'

安装 future 模块,由于使用sudo apt install future 提示找不到文件

我们执行 sudo apt install python3-future

 

再次运行测试文件:

报错 4:

Built target _regex

#1 Failure: ModuleNotFoundError (No module named 'hamcrest') ... ERROR

 

======================================================================

ERROR: Failure: ModuleNotFoundError (No module named 'hamcrest')

----------------------------------------------------------------------

Traceback (most recent call last):

  File "/usr/local/lib/python3.6/dist-packages/nose/failure.py", line 39, in runTest

    raise self.exc_val.with_traceback(self.tb)

  File "/usr/local/lib/python3.6/dist-packages/nose/loader.py", line 418, in loadTestsFromName

    addr.filename, addr.module)

  File "/usr/local/lib/python3.6/dist-packages/nose/importer.py", line 47, in importFromPath

    return self.importFromDir(dir_path, fqname)

  File "/usr/local/lib/python3.6/dist-packages/nose/importer.py", line 94, in importFromDir

    mod = load_module(part_fqname, fh, filename, desc)

  File "/usr/lib/python3.6/imp.py", line 245, in load_module

    return load_package(name, filename)

  File "/usr/lib/python3.6/imp.py", line 217, in load_package

    return _load(spec)

  File "<frozen importlib._bootstrap>", line 684, in _load

  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 678, in exec_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "/home/iwen/.vim/plugged/YouCompleteMe/python/ycm/tests/__init__.py", line 25, in <module>

    from ycm.tests.test_utils import MockVimModule

  File "/home/iwen/.vim/plugged/YouCompleteMe/python/ycm/tests/test_utils.py", line 28, in <module>

    from hamcrest import assert_that, equal_to

ModuleNotFoundError: No module named 'hamcrest'

安装  hamcrest 插件 

使用 sudo  apt install   hamcrest  将出现报错提示找不到相应的文件,文件版本比较多。

使用 sudo apt  search  hamcrest  出现以下结果:

google-mock/bionic 1.8.0-6 amd64

  Google's framework for writing and using C++ mock classes

 

googletest/bionic 1.8.0-6 amd64

  Google's C++ test framework

 

libhamcrest-java/bionic,bionic 1.3-7 all

  library of matchers for building test expressions

 

libhamcrest-java-doc/bionic,bionic 1.3-7 all

  library of matchers for building test expressions - documentation

 

libhamcrest1.2-java/bionic,bionic 1.2-0ubuntu1 all

  library of matchers for building test expressions

 

libhamcrest1.2-java-doc/bionic,bionic 1.2-0ubuntu1 all

  library of matchers for building test expressions - documentation

 

php-hamcrest/bionic,bionic 2.0.0-0ubuntu1 all

  This is the PHP port of Hamcrest Matchers

 

python-hamcrest/bionic,bionic 1.8.0-1 all

  Hamcrest framework for matcher objects (Python 2)

 

python3-hamcrest/bionic,bionic 1.8.0-1 all

  Hamcrest framework for matcher objects (Python 3)

 

我们安装 python3  的版本

 YouCompleteMe git:(master)  sudo apt install python3-hamcrest

再次运行测试文件,等待测试文件运行结束

#2 ycm.tests.client.base_request_test.BuildRequestData_AddWorkingDirWithFileName_test ... ok

#3 ycm.tests.client.base_request_test.BuildRequestData_AddWorkingDir_test ... ok

#4 ycm.tests.client.command_request_test.GoToResponse_QuickFix_test.GoTo_EmptyList_test ... ok

#5 ycm.tests.client.command_request_test.GoToResponse_QuickFix_test.GoTo_MultiItem_List_test ... ok

#6 ycm.tests.client.command_request_test.GoToResponse_QuickFix_test.GoTo_SingleItem_List_test ... ok

#7 ycm.tests.client.command_request_test.Response_Detection_test.BasicResponse_test('AnythingYouLike', True) ... ok

#7 ycm.tests.client.command_request_test.Response_Detection_test.BasicResponse_test('GoToEvenWorks', 10) ... ok

出现以上信息就说明youcomplete 已经不缺少相应的模块了。

然后执行  YouCompleteMe git:(master)   pyhthon3  install.py –clang-completer 我只安装了对c系列语言的自动补全,所以使用 --clang-completer,这部分可参考youcomplete项目的说明。

等待编译完成,此时就具有c和c++的补全功能

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值