You are not logged in.

#1 2014-05-29 20:46:55

davisd
Member
From: Fort Walton Beach, FL
Registered: 2010-03-10
Posts: 14
Website

Vim with Python 2 and Python 3 support (omnicomplete, virtualenv)

I am mostly a Python programmer these days with some of my projects using Python 2 and some using Python 3...  I am also a Vim user.  I use virtual environments (python-virtualenv and python2-virtualenv) for all of my Python projects.  At any time, my PATH'd ''python'' binary will either link to python2 or python3, depending on the virtual environment I have activated.

I needed a way to use the Python enabled Vim with omnicomplete, etc- no matter which version of Python my current project was using.

Vim can only be compiled with either Python 2 or Python 3 support, but not both.  It appears that gvim-python3 was recently added to extra.  Unfortunately, it conflicts with gvim-python, so that they cannot both be installed at the same time (understandably).

So I posted gvim-python3-noconflict in the AUR here:
https://aur.archlinux.org/packages/gvim … oconflict/

This installs a Python 3 enabled Vim into /opt/gvim-python3-noconflict/

And puts two scripts (launch-python-vim.sh and launch-python-gvim.sh) into /usr/bin/

The launch- scripts detect the major version of the current python executable and launch the appropriate version of vim or gvim.  If they launch the Python 3 enabled vim or gvim, they set the init vimrc file to ~/.vimrc-python3

So to use this,

  *  Install the Python 2 enabled **gvim** from the Arch maintained extra repo
  *  Install the Python 3 enabled **gvim-python3-noconflict** from the aur

To launch the correct version of vim or gvim, do:

$ launch-python-vim <file.py>

To make the correct vim and gvim launches transparent, I have the following two lines in my .bashrc:

alias vim='/usr/bin/launch-python-vim.sh'
alias gvim='/usr/bin/launch-python-gvim.sh'

To make full use of my Virtual Environments for omnicomplete, etc.- I have the following in my ~/.vimrc (for Python 2):

" VIRTUALENV setup
:python << EOF 
import os 
virtualenv = os.environ.get('VIRTUAL_ENV') 
if virtualenv: 
  activate_this = os.path.join(virtualenv, 'bin', 'activate_this.py') 
  if os.path.exists(activate_this): 
    execfile(activate_this, dict(__file__=activate_this)) 
EOF

And the following in my ~/.vimrc-python3 (for Python 3):

" VIRTUALENV setup
:python3 << EOF 
import os 
virtualenv = os.environ.get('VIRTUAL_ENV') 
if virtualenv: 
  activate_this = os.path.join(virtualenv, 'bin', 'activate_this.py') 
  if os.path.exists(activate_this): 
    exec(compile(open(activate_this).read(), activate_this, 'exec'), {'__file__': activate_this})
EOF

This is my first AUR submission- I hope that someone finds it useful!  Let me know if you have any suggestions or if something's broke.

The only future problem that I foresee as far as maintenance is concerned- is that the gvim-python3-noconflict package currently depends on vim-runtime-${pkgver}-${pkgrel} – so if the vim-runtime package is updated in the Arch maintained extra repo, the stock vim packages cannot be updated without first uninstalling gvim-python3-noconflict.

Would someone mind suggesting the best way to handle this? Would there be a downside to removing the version from the dependency, so that it simply depends on vim-runtime?

Thank you!
-David

Offline

#2 2014-05-29 21:24:41

GloW_on_dub
Member
Registered: 2013-03-13
Posts: 388

Re: Vim with Python 2 and Python 3 support (omnicomplete, virtualenv)

That's nice, but why do you need the exact dependance to this vim-runtime ?

Couldn't you just :

depends=(... 'vim-runtime>=7.4.307')

It may break with vim-runtime update, but whill not prevent user to update.

Offline

#3 2014-05-29 22:57:00

davisd
Member
From: Fort Walton Beach, FL
Registered: 2010-03-10
Posts: 14
Website

Re: Vim with Python 2 and Python 3 support (omnicomplete, virtualenv)

You're right, that would be better... Thank you.  Updated.

-David

Offline

#4 2014-05-29 23:38:43

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Vim with Python 2 and Python 3 support (omnicomplete, virtualenv)

Please remember to mark the thread as solved https://bbs.archlinux.org/viewtopic.php?id=130309

Offline

#5 2014-05-29 23:55:41

davisd
Member
From: Fort Walton Beach, FL
Registered: 2010-03-10
Posts: 14
Website

Re: Vim with Python 2 and Python 3 support (omnicomplete, virtualenv)

Why would we mark this thread solved?  I put together a package to help Archers in my situation that use vim to develop in Python 2 and Python 3. I created this post as instructions on how to use it.  Did I post this in the wrong spot perhaps?

Offline

#6 2014-05-30 00:15:34

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Vim with Python 2 and Python 3 support (omnicomplete, virtualenv)

Oh my goodness, I really mixed things up. I should have re-read the OP before replying. Instead, I just read the next two posts and I thought it was a completely different thread.
On top of that, turns out the "threads" I was thinking about are actually bug reports: https://bugs.archlinux.org/task/40591 and https://bugs.archlinux.org/task/34397

Sorry for the noise.

Offline

#7 2014-05-30 00:55:23

davisd
Member
From: Fort Walton Beach, FL
Registered: 2010-03-10
Posts: 14
Website

Re: Vim with Python 2 and Python 3 support (omnicomplete, virtualenv)

No problem!

Offline

Board footer

Powered by FluxBB