开发者

Vim with python support enviromental variables

If i type in the vim command line

:python import os;print os.getenv('PYTHONPATH')

I get a path If i close vim and on the same terminal do

echo $PYTHONPATH

I get another completly different path Why is this, where is vim getting this path? This is relevant because the autocompletion can't find the modules thus it doesnt work. I know this because if i try, again from the vim cli

:python import django

It fails But if i exit vim and type

python
>>> import django

No errors are shown! Whats going on here? I'm using virtualenv and i checked the activate source and is not changing the PYTHONPATH. I tried this without virtualenv, same problem.

Update: The line i used to configure the V开发者_开发知识库im source prior to compiling it

./configure --prefix=${HOME}/apps/vim73 --with-features=huge --enable-gui=gnome2 --enable-pythoninterp --enable-rubyinterp --enable-multibyte --with-python-config-dir=/usr/lib/python2.6/config


PYTHONPATH is a red herring: that's not what the virtualenv uses to configure itself. The virtualenv works by adding a prefix to PATH that points to the location of an alternate python executable, overriding the system python.

The problem with Vim is that the Python embedding does not look at the Python executable or PATH: it looks for and loads the libpython library, which virtualenv does not virtualize. This means that Vim will always initialize the system Python, regardless of any virtualenv.

However, all is not lost: Vim can still run the virtualenv's initialization script after its own Python initialization. Jeremy Cantrell wrote a Vim plugin to help automate this, which should solve your problem:

  • https://github.com/jmcantrell/vim-virtualenv
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜