VIM: use python3 interpreter in python mode

I recently switched to vim and configured it for Python programming using this tutorial. Before that, I made sure that vim supports python3 (vim -version shows + python / dyn and + python3 / dyn) using this article.

But when executing the file from python-mode , the python2.7 interpreter is still selected.

How to configure vim (or python mode) to run files in python3 interpreter?

My OS is Ubuntu 14.04 x64.

Thanks in advance!

+5
source share
4 answers

Try adding this to your .vimrc file

let g:pymode_python = 'python3' 

I found this in the help docs. In vim type:

 :help python-mode 

By default, vim is not compiled with python3 support, so when I tried it, I got all kinds of errors ... Which tells me that it is trying to use python3. But if your vim --version output shows + python3, you should be good.

EDIT: By default, Ubuntu 14.04 does not support + python3. And due to limitations you cannot support both python2 and python3.

So you need to compile vim with python3 support.

These are the steps that worked for me: from the linux command line:

Install packages

 sudo apt-get install checkinstall mercurial python-dev python3-dev ruby ruby-dev libx11-dev libxt-dev libgtk2.0-dev libncurses5 ncurses-dev 

Take the latest version of vim

 hg clone https://vim.googlecode.com/hg/ vim 

Customize it

 cd vim ./configure \ --enable-perlinterp \ --enable-python3interp \ --enable-rubyinterp \ --enable-cscope \ --enable-gui=auto \ --enable-gtk2-check \ --enable-gnome-check \ --with-features=huge \ --enable-multibyte \ --with-x \ --with-compiledby="xorpd" \ --with-python3-config-dir=/usr/lib/python3.4/config-3.4m-x86_64-linux-gnu \ --prefix=/opt/vim74 

Compile it

 make 

Check him

 make test 

Install it

 sudo checkinstall 

Tie the package

 sudo ln -s /opt/vim74/bin/vim /usr/bin/vim-py3 

You now have both versions of vim

To use the regular vim type (python2) vim file.py

To use vim with support for type python3 vim-py3 file.py

If you just need the python3 version, you will only need to associate it with the new vim

 ln -s /opt/vim74/bin/vim /usr/local/bin/vim 

And if you want to return to the python2 version, remove the link

 rm /usr/local/bin/vim 
+17
source

removes python 2.X

The symlink ( /usr/bin/vim /etc/alternatives/vim ) becomes useless, possibly because the vim executable is removed from /etc/alternatives

+1
source

I removed the symbolic link (/ usr / bin / vim) since it no longer works and redid vim

 ln -s /opt/vim74/bin/vim /usr/bin/vim 
0
source

I also met the same problem. My device is a Mac, so it may be a little different. I use Homebrew to manage my packages.

brew install vim download Vim from Python.

So you can download Vim from Python 3 with brew install vim --with-python3 --HEAD

There may be other operations. You may need something like brew unlink vim .

0
source

All Articles