VIM:在 python 模式下使用 python3 解释器 [英] VIM: Use python3 interpreter in python-mode
问题描述
我最近切换到 vim 并使用 本 教程.之前,我使用 这篇 文章.
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.
但是当从 python-mode 执行文件时,仍然选择了 python2.7 解释器.
But when executing a file from python-mode, still the python2.7 interpreter is chosen.
如何配置 vim(或 python 模式)以在 python3 解释器上运行文件?
How can I configure vim (or the python-mode) to run files on the python3 interpreter?
我的操作系统是 Ubuntu 14.04 x64.
My OS is Ubuntu 14.04 x64.
提前致谢!
推荐答案
尝试将其添加到您的 .vimrc 文件中
Try adding this to your .vimrc file
let g:pymode_python = 'python3'
我在帮助文档中找到了这个.在 vim 类型中:
I found this in the help docs. In vim type:
:help python-mode
默认情况下,vim 不支持 python3 编译,所以当我尝试这个时,我遇到了各种各样的错误......这告诉我它正在尝试使用 python3.但是如果你的 vim --version
输出显示 +python3 你应该没问题.
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.
默认情况下,Ubuntu 14.04 不支持 +python3.并且由于限制,您不能同时拥有 python2 和 python3 支持.
By default, Ubuntu 14.04 doesn't come with +python3 support. And due to limitations, you can't have both python2 and python3 support.
所以,你必须编译支持 python3 的 vim.
So, you have to compile vim with python3 support.
这些是对我有用的步骤:从 linux 命令行:
These are the steps that worked for me: From a linux command line:
安装软件包
sudo apt-get install checkinstall mercurial python-dev python3-dev ruby ruby-dev libx11-dev libxt-dev libgtk2.0-dev libncurses5 ncurses-dev
获取最新版本的vim
hg clone https://vim.googlecode.com/hg/ vim
配置
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
编译
make
测试一下
make test
安装
sudo checkinstall
链接包
sudo ln -s /opt/vim74/bin/vim /usr/bin/vim-py3
现在,您拥有两个版本的 vim
Now, you have both versions of vim
要使用普通的 vim (python2) 输入 vim file.py
To use normal vim (python2) type vim file.py
使用带有python3支持类型的vim vim-py3 file.py
To use vim with python3 support type vim-py3 file.py
如果你只想要python3版本,那么你只需要链接到新的vim
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
如果你想切换回python2版本,去掉链接
And if you want to switch back to the python2 version, remove the link
rm /usr/local/bin/vim
这篇关于VIM:在 python 模式下使用 python3 解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!