Vim在OS X上无法与Python编译
我一直在尝试在mac OS X 10.6上编译vim 7.3,希望能支持python 2.7。编译vim本身没有问题,但嵌入的python就不太顺利。
我采取的步骤如下:
hg clone https:/vim.googlecode.com/hg/ vim
cd vim/src
./configure --without-x --disable-gui --disable-darwin \
--enable-pythoninterp --with-features=huge
make
make install
这样我得到了一个可以用的vim,但没有python支持。
在auto/config.log文件中显示有一个文件错误:
configure:5387: checking if compile and link flags for Python are sane
configure:5404: gcc -o conftest -g -O2
-I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
-DPYTHON_HOME=\"/Library/Frameworks/Python.framework/Versions/2.7\"
-L/usr/local/lib conftest.c
-L/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
-lpython2.7 -ldl -framework CoreFoundation
-u _PyMac_Error Python.framework/Versions/2.7/Python >&5
i686-apple-darwin10-gcc-4.2.1: Python.framework/Versions/2.7/Python: No such file or directory
<command-line>: warning: missing terminating " character
configure:5404: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define UNIX 1
| #define STDC_HEADERS 1
| #define HAVE_SYS_WAIT_H 1
| #define FEAT_HUGE 1
| #define USE_XSMP_INTERACT 1
| /* end confdefs.h. */
|
| int
| main ()
| {
|
| ;
| return 0;
| }
configure:5408: result: no: PYTHON DISABLED
无论我是否使用--with-python-conf-dir这个选项运行配置,我都会遇到这个错误。看起来-u _PyMac_Error Python.framework/Versions/2.7/Python
是问题的根源,但我不知道接下来该怎么做。
有没有什么建议?
3 个回答
这个回答并没有直接回答你的问题,但你可以通过安装macports,然后运行命令sudo port install vim +python27
来实现你的目标。
结果发现这个问题其实出在Python的Makefile里,真是让人意想不到。
打开这个文件
/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
或者根据你的情况找到合适的路径,然后搜索 PyMac_Error
。这个内容应该在定义 LINKFORSHARED
的那一行。在这一行,你需要把 PYTHONFRAMEWORKDIR
改成 PYTHONFRAMEWORKINSTALLDIR
。然后回到你的vim源文件,运行 ./configure,接下来一切应该就顺利了。
另外,确保你把OS X的Python框架链接到Homebrew的库里:
/Library/Frameworks/Python.framework/Versions/2.7
/Library/Frameworks/Python.framework/Versions/Current
/System/Library/Frameworks/Python.framework/Versions/2.7
/System/Library/Frameworks/Python.framework/Versions/Current
这些链接应该都指向
/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7
我也不太明白为什么我在这么多地方都有这个,或者这样是否不好,但就是这样。
Romainl 提供了一个被接受的答案:MacVim 除了有图形界面的版本外,还自带了命令行版本的 vim,这点我之前并不知道。而且我已经成功地用 Python 2.7 编译了 MacVim(没有遇到标准 vim 源码中那些问题)。
我并没有考虑使用 macports 或 homebrew。
注意:如果有人能把这个答案归给 Romainl,请随意去做。我只是自己回答一下,以便结束这个话题。