VIM: Use python3 interpreter in python-mode

女生的网名这么多〃 提交于 2019-12-20 09:44:53

问题


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

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

How can I configure vim (or the python-mode) to run files on the python3 interpreter?

My OS is Ubuntu 14.04 x64.

Thanks in advance!


回答1:


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 this, I got all kinds of errors... Which tells me it's trying to use python3. But if your vim --version output shows +python3 you should be good.

EDIT: By default, Ubuntu 14.04 doesn't come with +python3 support. And due to limitations, you can't have both python2 and python3 support.

So, you have to compile vim with python3 support.

These are the steps that worked for me: From a 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

Grab the latest version of vim

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

Configure 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

Test it

make test

Install it

sudo checkinstall

Link the package

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

Now, you have both versions of vim

To use normal vim (python2) type vim file.py

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

If you just want the python3 version, then you only need to link it to the new vim

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

And if you want to switch back to the python2 version, remove the link

rm /usr/local/bin/vim



回答2:


it removes python 2.X

The symbolic link (/usr/bin/vim -> /etc/alternatives/vim) is become useless, probably because the vim executable deleted from /etc/alternatives




回答3:


I removed the The symbolic link (/usr/bin/vim) since it does not work any more and relinked the vim

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



回答4:


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

brew install vim will download Vim with Python.

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

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



来源:https://stackoverflow.com/questions/30444890/vim-use-python3-interpreter-in-python-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!