29

I am running Debian Jessie and use the current vim-nox (with +python -python3). I am having a hard time trying to program in Python 3, as I struggle with Python 3 code completion.

YouCompleteMe doesn't support Python3 at all. jedi-vim does support Python 3 completion, but only if I would have the +python3 option if I understand it correctly. From several posts from Debian Developers it seems that compiling Vim with the +python3 flag is not really working. Therefore I am left with the python-mode plugin.

Besides the fact that python-mode seems unmaintained (see open pull-requests and last commits) and it currently has a huge bug concerning rope in its master branch, it interferes with YouCompleteMe. I do get some Python 3 code completion to work, but only if I disable YouCompleteMe totally. Blacklisting YCM for python filetypes or disabling YCM completion for python files doesn't work, I get a YCM warning each time I open vim.

So my questions are:

How can I get a Python 3 autocompletion to work on a current Debian distribution while not deactivating YouCompleteMe (which I want for other programmming languages)? How come an unmaintained plugin is the only choice at the moment for code completion for such an important programming language (Python 3 can no longer be considered new..)?

8
  • 2
    "How come an unmaintained plugin is the only choice at the moment for code completion for such an important programming language" -> There are almost no Python 3-only projects, almost all Python programs run fine on Python 2 & 3, so Python 2 completion should be good for almost everyone. Mar 7, 2015 at 4:31
  • Agreed with @Carpetsmoker. Vim comes with Python completion out of the box, and it works wonders with Python3 as well. In fact, the default pythoncomplete that comes built in to Vim is what I use. No YCM, no Jedi-vim, no Python-mode. See my answer if you still want +python3
    – akshay
    Mar 7, 2015 at 4:44
  • I just checked out pythoncomplete, I didn't know that this script is included in a normal vim installation. That is definetely a nice basic option. Do you happen to know an easy way for pythoncomplete to add brackets to functions call (e.g. print(''))?
    – xt440
    Mar 7, 2015 at 6:05
  • I think you would have to modify that yourself. The source is available here on vim.org: vim.org/scripts/script.php?script_id=1542. Admittedly, it is pretty old, but it works pretty well for me.
    – akshay
    Mar 7, 2015 at 9:12
  • github.com/klen/python-mode Mar 7, 2015 at 14:21

6 Answers 6

18

The ideal way is to get Vim's source and compile it yourself.

Step 1: For Debian-like systems, get the required packages:

sudo apt-get build-dep vim

Step 2: Clone Vim's source code:

cd /tmp && git clone https://github.com/vim/vim.git && cd vim

Step 3: Configure, Make, Install

./configure --with-features=huge --enable-multibyte --enable-python3interp \
    --enable-gui=gtk-2 --prefix=/usr

make VIMRUNTIMEDIR=/usr/share/vim/vim74
sudo make install

Step 4: Done! You should have a huge version of vim, with +python3 support. It also has +clipboard support so you can use it with your system clipboard, and a gui version.

Of course, you can remove configure flags you don't want or add some in. YouCompleteMe actually has a fairly length wiki dedicated to explaining how to build Vim from source here

7
  • Thanks for your quick answer. I was able to build vim with +python3/dyn and +python/dyn support. But that does not solve my problem. As soon as I start vim, YouCompleteMe starts (which always starts python2 as far as I know). When I enter :echo has('python3') I get 0, whereas :echo has('python') returns 1. I have the following options in my .vimrc, but they don't help: let g:ycm_path_to_python_interpreter = '/usr/bin/python3 let g:ycm_filetype_specific_completion_to_disable = { 'python' : 1 } let g:ycm_filetype_blacklist = { 'python' : 1 }.
    – xt440
    Mar 7, 2015 at 5:41
  • For step 1, I recommend instead: apt-get build-dep vim Mar 7, 2015 at 11:21
  • @200_success, I'm not sure if that also pulls down the x11 stuff needed for clipboard support. I don't have a linux machine with me to check though.
    – akshay
    Mar 7, 2015 at 11:24
  • From packages.debian.org/jessie/vim, see the .dsc file linked in the sidebar. I believe all of the packages you suggested, except mercurial, are either directly or transitively listed as Build-Depends. In particular, libgnomeui-dev is probably responsible for many of those dependencies. Mar 7, 2015 at 11:37
  • @200_success, fair enough, thanks! Updated the post.
    – akshay
    Mar 7, 2015 at 11:41
5

jedi-vim works fine for me now with +python3 support in vim. In added the following option to my .vimrc: let g:jedi#force_py_version = 3.

4

Writing this more as a note to myself than anything, but maybe this will be useful to some: on Arch Linux, you can install a version of vim compiled with python3:

# pacman -S vim-python3
resolving dependencies...
looking for conflicting packages...
:: vim-python3 and vim are in conflict. Remove vim? [y/N] y

Type y and this will replace your existing vim with the python3 enabled vim.

Then:

# pacman -S vim-jedi

will install the autocompletion, for python3.

4

Since a couple of weeks, YouCompleteMe does support Python3 completion using Jedi via a JediHTTP wrapper. Only install YouCompleteMe (no need to install jedi-vim) according to the installation instructions and add the following line to your .vimrc:

let g:ycm_python_binary_path = '/usr/bin/python3'

This forces YCM to use Jedi with Python3 (default is to use Jedi with the same Python interpreter that is used by the ycmd server, which is Python2).

This works no matter if your Vim is compiled with or without the +python3 flag - you get Python3 autocompletion (and documentation look up and more).

1

I'm in a position where I have to constantly switch between two python projects, one using python 2 the other python 3. As you noted youcompleteme does not work with python 3.

First I compiled an additional version of vim with python 3 (which I start with vim3) and I use vundle as plugin manager.

In my .vimrc I have:

Plugin 'davidhalter/jedi-vim' " for python3
Plugin 'Valloric/YouCompleteMe' " for python2


if has('python3')
    let g:loaded_youcompleteme = 1 " disables loading it! doesnt support python3
    let g:jedi#force_py_version = 3
    let g:pymode_python = 'python3'

It disables youcompleteme when I run vim3, but I have the jedi-vim autocomplete instead. I only just started using it, and this blog post says they are not compatible together but for me autocomplete works in both, jedi's go-to-definition works, python-mode's pylint works and no plugin complains on startup. All good so far :)

0

Use deoplete and deoplete-jedi if you are open to neovim. In my experience this works quite well, where YCM has a bit of hassles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.