如何在Ubuntu14.04+上编译同时支持python2和python3的vim?

详细请见:

https://askubuntu.com/questions/612285/how-to-build-deb-files-of-vim-which-support-both-python2-and-python3-on-ubuntu1


It seems on Debian-based systems (at least) you can't have your cake and eat it too. It's either Python 2 or Python 3. Due to how the Python libraries are built, you can only use one variant within a Vim session. You can build with both, but if Python 2 is called in Vim, then Python 3 cannot be called in the same session, and vice versa. On Arch Linux as well, Vim is only compiled with one of Python 2 (vimgvim) or Python 3 (vim-python3gvim-python3).

To rebuild the Vim that the repositories provide:

sudo apt-get build-dep vim
apt-get source vim
cd vim-*  # it will be vim-7.4.something

Edit debian/rules and replace:

ALLINTERPFLAGS+=--enable-pythoninterp --with-python-config-dir=$(shell python-config --configdir)
ALLINTERPFLAGS+=--disable-python3interp

With:

ALLINTERPFLAGS+=--enable-pythoninterp=dynamic --with-python-config-dir=$(shell python-config --configdir)
ALLINTERPFLAGS+=--enable-python3interp=dynamic --with-python3-config-dir=$(shell python3-config --configdir)

Then run:

DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -rfakeroot -us -uc -b

(备注:这里在原教程中是 dpkg-buildpackage -us -uc ,但是在我的ubuntu上运行失败,上面的是运行成功的)

Have lunch. (Or tea if you used -j $(nproc).)

Now, multiple .deb files will have been created in the parent directory. To see which:

cd ..
ls vim*.deb

Along with the particular variant you want to install (vimvim-gnomevim-gtk, etc.), you'll have to install vim-common_*.debvim-runtime_*.deb, and for the GUI versions, vim-gui-common_*.deb. For example, with vim-gnome, and the current version of vim in the repositories:

sudo dpkg -i vim-gnome_7.4.052-1ubuntu3_amd64.deb vim-common_7.4.052-1ubuntu3_amd64.deb vim-gui-common_7.4.052-1ubuntu3_all.deb vim-runtime_7.4.052-1ubuntu3_all.deb

Then:

$ vim --version | grep python
+cryptv          +linebreak       +python/dyn      +viminfo
+cscope          +lispindent      +python3/dyn     +vreplace

The pi-rho/dev PPA builds Vim in this fashion, so you cna use the PPA instead of manually building it.


你可能感兴趣的:(ubuntu,vim)