Python-enabled vim

If I find the vim command line

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

I get the path if I close vim and on the same terminal do

 echo $PYTHONPATH 

I get another completely different path. Why is this where vim gets this path? This is relevant because autocomplete cannot find modules, so it does not work. I know this because if I try again from vim cli

 :python import django 

It fails, but if I exit vim and print

 python >>> import django 

There are no errors! What's going on here? I am using virtualenv and I checked the activation source and did not change PYTHONPATH. I tried this without virtualenv, the same problem.

Update: The line I used to configure the Vim source before 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

+6
source share
1 answer

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

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

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

+4
source

Source: https://habr.com/ru/post/897729/


All Articles