简体   繁体   English

Vim与python支持环境变量

[英]Vim with python support enviromental variables

If i type in the vim command line 如果我输入vim命令行

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

I get a path If i close vim and on the same terminal do 我得到一条路径如果我关闭vim并在同一个终端上做

echo $PYTHONPATH

I get another completly different path Why is this, where is vim getting this path? 我得到另一个完全不同的路径为什么这样,vim在哪里获得这条路径? 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 我知道这是因为如果我尝试再次从vim cli

:python import django

It fails But if i exit vim and type 它失败但如果我退出vim并输入

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. 我正在使用virtualenv并且我检查了激活源并且没有更改PYTHONPATH。 I tried this without virtualenv, same problem. 我试过这个没有virtualenv,同样的问题。

Update: The line i used to configure the Vim source prior to compiling it 更新:用于在编译之前配置Vim源的行

./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 ./configure --prefix = $ {HOME} / apps / vim73 --with-features = huge --enable-gui = gnome2 --enable-pythoninterp --enable-rubyinterp --enable-multibyte --with-python-配置-DIR = / usr / lib中/ python2.6的/配置

PYTHONPATH is a red herring: that's not what the virtualenv uses to configure itself. PYTHONPATH是一个红鲱鱼:这不是virtualenv用来配置自己的东西。 The virtualenv works by adding a prefix to PATH that points to the location of an alternate python executable, overriding the system python . virtualenv的工作原理是向PATH添加一个前缀,指向备用python可执行文件的位置,覆盖系统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. Vim的问题是Python嵌入不会查看Python可执行文件或PATH :它查找并加载libpython库,virtualenv不会虚拟化。 This means that Vim will always initialize the system Python, regardless of any virtualenv. 这意味着Vim将始终初始化系统Python,而不管任何virtualenv。

However, all is not lost: Vim can still run the virtualenv's initialization script after its own Python initialization. 但是,一切都不会丢失:Vim仍然可以在自己的Python初始化之后运行virtualenv的初始化脚本。 Jeremy Cantrell wrote a Vim plugin to help automate this, which should solve your problem: Jeremy Cantrell写了一个Vim插件来帮助自动化,这可以解决你的问题:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM