3

I am trying to compile vim against EPD Canopy's python, but the ./configure can't seem to find the correct config directory. Here is the command I am running

CC=clang ./configure --prefix=/usr/local \
              --with-features=huge \
              --enable-rubyinterp \
              --enable-pythoninterp \
              --enable-perlinterp \
              --enable-cscope

And this is the relevant part of the output

checking --enable-pythoninterp argument... yes
checking for python... /Users/noah/Library/Enthought/Canopy_64bit/User/bin/python
checking Python version... 2.7
checking Python is 1.4 or better... yep
checking Python's install prefix... /Users/noah/Library/Enthought/Canopy_64bit/User
checking Python's execution prefix... /Users/noah/Library/Enthought/Canopy_64bit/User
checking Python's configuration directory...
can't find it!

Now, there is a config directory in the Canopy.app bundle, so I also tried adding the flag --with-python-config-dir=/Applications/Canopy.app/Contents/lib/python2.7/config. Which gave the error

checking if compile and link flags for Python are sane... no: PYTHON DISABLED

enI am out of ideas. Thanks for your help.

cjh
  • 866
  • 4
  • 16
nbren12
  • 634
  • 1
  • 7
  • 11

2 Answers2

2

Make sure to run make distclean first to get rid of anything cached from your failed builds.

The following works for me (on Debian Wheezy 64 bit) (you'll need to change $VIM_SRC and $CANOPY_SRC to wherever you have your vim and canopy dirs).

VIM_SRC=~/src/vim73
CANOPY_SRC=~/src/canopy

cd $VIM_SRC                                                         
make distclean                                                                 
# Compile against canopy python and install in canopy dir, so that             
# this vim is used when canopy is activated.                                   
# YOU HAVE TO HAVE CANOPY ACTIVATED, i.e. `which python` points to canopy   
# you also need python-config 
# (this assumes you can install into your canopy install 
# dir, but it isn't strictly necessary)                                    
APPDATA=$CANOPY_SRC/appdata/canopy-1.0.3.1262.rh5-x86_64                  
PYTHON_CONFIG=$APPDATA/lib/python2.7/config 
# I'm installing here so that this is the vim used when I start the virtualenv,
# but you can put it where you like. 
INSTALL_DIR=$CANOPY_SRC/Enthought/Canopy_64bit/User/ 

# force vim to use this python binary                                          
export vi_cv_path_python=$APPDATA/bin/python                                   
./configure --prefix=$INSTALL_DIR \                                
    --with-features=big \                                                      
    --enable-pythoninterp=yes \                                                
    --with-python-config-dir=$PYTHON_CONFIG \                                  
    # I didn't actually need these flags. python-config is a helper script
    # that comes with the Debian package python-dev. I'm leaving them here
    # in case someone finds them useful.
    # CFLAGS="`python-config --includes`" \                                      
    # LIBS="`python-config --libs`" \
    # LDFLAGS="`python-config --ldflags`"                                             
make                                                                           
make install   

The trick is setting vi_cv_path_python to force vim to use the python that can import site.

Test with

vim -c ':py import os; print os.__file__'

This won't be able to import shared objects, e.g vim -c ':py import zmq'. LD_LIBRARY_PATH can fix this.

Call vim after setting LD_LIBRARY_PATH:

alias vim="LD_LIBRARY_PATH='$APPDATA/lib' vim"

Problems

Older versions of Vim will fail if you use CFLAGS="python-config --cflags" or don't give this at all. This is because this includes -O2 in the gcc args and this will cause vim to segfault. This is why I've put --includes. My solution works with the latest development snapshot.

Community
  • 1
  • 1
aaren
  • 5,325
  • 6
  • 29
  • 24
0

This looks like it's because Canopy doesn't make a framework the way EPD and system python do, and MacVim uses a -framework option during compile. You can make this work by setting up some symlinks, and modifying a few paths in the compile process.

  • First, make a Python.framework symlink in /System/Library to the Python files in /Applications/Canopy.app as follows (modify as needed depending on your version of Canopy): ln -s /Applications/Canopy.app/appdata/canopy-1.0.3.1262.macosx-x86_64/Canopy.app/Contents

  • Run the configure script with the options you like (I omit the python-config-dir): ./configure --with-features=huge --enable-rubyinterp --enable-pythoninterp --enable-perlinterp --enable-cscope --disable-netbeans

  • Modify src/auto/config.mk as follows:

PYTHON_CFLAGS=-I/Applications/Canopy.app/appdata/canopy-1.0.3.1262.macosx-x86_64/Canopy.app/Contents/include/python2.7 -DPYTHON_HOME='"/Applications/Canopy.app/appdata/canopy-1.0.3.1262.macosx-x86_64/Canopy.app/Contents"'

PYTHON_GETPATH_CFLAGS= ..(whatever is generated by config).... -DPREFIX='"/Applications/Canopy.app/appdata/canopy-1.0. 3.1262.macosx-x86_64/Canopy.app/Contents"' -DEXEC_PREFIX='"/Applications/Canopy.app/appdata/canopy-1.0.3.1262. macosx-x86_64/Canopy.app/Contents"'

  • Edit src/if_python.c (line 59) to read # include Python.h instead of Python/Python.h

  • This should compile correctly. However, there's an rpath issue when running vim that I'm not experienced enough understand (if you know about it, please share). So I get around the issue by simply making a symlink in /usr/lib to the Python library:

ln -s /Applications/Canopy.app/appdata/canopy-1.0.3.1262.macosx-x86_64/Canopy.app/Contents/Python /usr/lib/Python

You could also export a DYLD_LIBRARY_PATH, but one shouldn't have to do something like this-- an executable should be built knowing where to find its libraries. But as I said, I'm an amateur.