使用特定版本的Python编译vim
我正在开发几个在不同版本的 Python 上运行的 Python 项目。我希望设置我的 vim 环境以使用 Ropevim、pyflakes 和 pylint,但我遇到了由于使用单个 vim 引起的一些问题(针对特定版本的 Python 编译,与项目的 Python 版本不匹配) 。
我希望将 vim 构建到我的每个 virtualenv 目录中,但我遇到了问题并且无法让它工作。当我尝试从源代码构建 vim 时,尽管在 virtualenv 中指定了 Python 配置文件夹,但始终使用系统范围的 Python 解释器。
目前,我安装了 Python 2.6.2 和 Python 2.7.1,并从每个版本创建了多个 virtualenv。我使用的是 Ubuntu 10.04,系统默认的 Python 是 2.6.5。每次我编译 vim 并调用 :python import sys; print(sys.version)
它返回 Python 2.6.5
。
configure --prefix=/virtualenv/project --enable-pythoninterp=yes --with-python-config-dir=/virtualenv/project/lib/python2.6/config
结果如下config.log:
...
configure:5151: checking --enable-pythoninterp argument
configure:5160: result: yes
configure:5165: checking for python
configure:5195: result: /usr/bin/python
...
应该是 /virtualenv/project/bin/python
。有没有办法指定vim使用的Python解释器?
注意:我可以确认 /virtualenv/project/bin 出现在 PATH
环境变量的前面。
I'm working on several Python projects who run on various versions of Python. I'm hoping to set up my vim environment to use ropevim, pyflakes, and pylint but I've run into some issues caused by using a single vim (compiled for a specific version of Python which doesn't match the project's Python version).
I'm hoping to build vim into each of my virtualenv directories but I've run into an issue and I can't get it to work. When I try to build vim from source, despite specifying the Python config folder in my virtualenv, the system-wide Python interpreter is always used.
Currently, I have Python 2.6.2 and Python 2.7.1 installed with several virtualenvs created from each version. I'm using Ubuntu 10.04 where the system-default Python is 2.6.5. Every time I compile vim and call :python import sys; print(sys.version)
it returns Python 2.6.5
.
configure --prefix=/virtualenv/project --enable-pythoninterp=yes --with-python-config-dir=/virtualenv/project/lib/python2.6/config
Results in the following in config.log:
...
configure:5151: checking --enable-pythoninterp argument
configure:5160: result: yes
configure:5165: checking for python
configure:5195: result: /usr/bin/python
...
It should be /virtualenv/project/bin/python
. Is there any way to specify the Python interpreter for vim to use?
NOTE: I can confirm that /virtualenv/project/bin appears at the front of PATH
environment variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我建议针对 2 个解释器构建 vim,然后使用下面提供的 shell 脚本调用它,将其指向特定的 virtualenv。
我能够使用以下命令针对 Python 2.7 构建 vim(2.7 安装在 $HOME/root 下):
你的 virtualenv 实际上是一个围绕 Python 解释器的薄包装器,它是用 --
$HOME/foobar/lib 创建的/python2.6/config
是到/usr/lib/python2.6/config
的符号链接。因此,如果您使用系统解释器创建它,VIM 将探测这一点并最终链接到真正的解释器,默认情况下使用系统
sys.path
,即使配置将显示 virtualenv 的路径:解决方法:由于您的系统 vim 很可能是针对系统 python 进行编译的,因此您无需为每个 virtualenv 重建 vim:您只需将名为
vim
的 shell 脚本放入你的 virtualenv 的 bin 目录,其中在调用系统 vim 之前扩展 PYTHONPATH:~/HOME/foobar/bin/vim
的内容:调用时,将插入 virtualenv 的 sys.path:
I'd recommend building vim against the 2 interpreters, then invoking it using the shell script I provided below to point it to a particular virtualenv.
I was able to build vim against Python 2.7 using the following command (2.7 is installed under $HOME/root):
Your virtualenv is actually a thin wrapper around the Python interpreter it was created with --
$HOME/foobar/lib/python2.6/config
is a symlink to/usr/lib/python2.6/config
.So if you created it with the system interpreter, VIM will probe for this and ultimately link against the real interpreter, using the system
sys.path
by default, even though configure will show the virtualenv's path:The workaround: Since your system vim is most likely compiled against your system python, you don't need to rebuild vim for each virtualenv: you can just drop a shell script named
vim
in your virtualenv's bin directory, which extends the PYTHONPATH before calling system vim:Contents of
~/HOME/foobar/bin/vim
:When that is invoked, the virtualenv's sys.path is inserted:
无论如何,似乎没有人在这里回答这个问题,我很幸运地使用了如下命令行:
For what it's worth, and no one seems to have answered this here, I had some luck using a command line like the following:
我想为crowder提供一个类似的解决方案,该解决方案对我来说非常有效。
假设您已将 Python 安装在 /opt/Python-2.7.5 中,并且该文件夹的结构是
,并且您希望使用该版本的 Python 构建 vim。您需要做的就是
因此,只需将
vi_cv_path_python
变量显式提供给configure
,脚本就会自行推断出所有内容(甚至是配置目录)。这在 vim 7.4+ 上进行了多次测试,最近又在
vim-7-4-324
上进行了多次测试。I would like to give a similar solution to crowder's that works quite well for me.
Imagine you have Python installed in /opt/Python-2.7.5 and that the structure of that folder is
and you would like to build vim with that version of Python. All you need to do is
Thus, just by explicitly giving
vi_cv_path_python
variable toconfigure
the script will deduce everything on its own (even the config-dir).This was tested multiple times on vim 7.4+ and lately with
vim-7-4-324
.我的系统上的 3 个不同版本的 python 也遇到了同样的问题。
对我来说,最简单的事情是更改我的
$PATH
环境变量,以便具有我想要的 python 版本的文件夹是(在我的情况下/usr/local/bin
)先于另一个被发现。I was having this same issue with 3 different versions of python on my system.
for me the easiest thing was to change my
$PATH
env variable so that the folder that has the version of python I wanted was (in my case/usr/local/bin
) was found before another.在我编译vim80的过程中,系统python是2.6,我在~/local/bin下有另一个python 2.7,我发现,为了使编译工作:
During my compiling vim80, the system python is 2.6, I have another python 2.7 under ~/local/bin, I find that, to make the compiling work: