7

I've been trying to compile vim 7.3 with python 2.7 support on mac OS X 10.6. Vim itself compiles fine, but the embedded python not so much.

The steps I've taken:

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

That gives me a working vim but without python.

The auto/config.log indicates there's a file error:

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

I get this error whether I run configure with or without the --with-python-conf-dir option. It looks like the -u _PyMac_Error Python.framework/Versions/2.7/Python is the source of the problem, but I'm not sure where to go from here.

Any suggestions?

Mark Gemmill
  • 5,889
  • 2
  • 27
  • 22
  • 1
    I'm running 10.6.7 and the latest Apple-supplied python I have is 2.6. Are you sure you have 2.7 installed and is it located in `System/Library/Frameworks/Python.framework/`? If you want to use a different python you'll probably need to provide its path at `./configure` time or make sure it is the default `python`. Anyway, MacVim comes with a full-featured command-line `vim`, why don't you try it? – romainl Jun 27 '11 at 12:12
  • Romaini, **python 2.7** is definitely installed in the correct place and is set to the **Current** python. `./configure` fails the python check regardless of whether I supply it the path or not. `_PyMac_Error` bit is obviously supplying a relative path which is causing the problem. MacVim is what I use but I wasn't aware that I could invoke MacVim as a command-line app. It actually solves the problem as I already have it compiled it against Python 2.7 and it's the current Vim 7.3 (mac 10.6 vim is 7.2 - which is the reason I started down this road to begin with). – Mark Gemmill Jun 27 '11 at 16:37
  • That's cool. I'm sorry I haven't been able to help with the Python issue though. I went the same road at one time (with ruby which was needed by a bunch of cool plugins). Discovering the `vim` executable in MacVim's bundle solved sooo many things at once. – romainl Jun 27 '11 at 19:00
  • Romainl, I figured if there was no easy answer, I'd probably end up looking at how MacVim dealt with the issue anyway (they must do something different than standard vim for handling the python option, because MacVim compiles with python super easy). Thanks for the tip! If you want to officially answer this one, we'll go with that as THE answer. "Practicality beats purity" as python folk say. – Mark Gemmill Jun 27 '11 at 23:07
  • I had a similar problem with macOS Monterey 12.1 and Python 3.10.1 when trying to compile libimobiledevice, libelist, and libimobiledevice-glue-1.0. The fix was to change /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/_sysconfigdata__darwin_darwin.py Lines 570-571 'LINKFORSHARED': '-Wl,-stack_size,1000000 -framework CoreFoundation ' 'Python.framework/Versions/3.10/Python', 'LINKFORSHARED': '-Wl,-stack_size,1000000 -framework CoreFoundation ' '/Library/Frameworks/Python.framework/Versions/3.10/Python', ... continued – user1260486 Jan 04 '22 at 18:56
  • ...continuation the above change allowed me to continue with my compilation. I also did the same to the following file (just in case scenario) /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/config-3.10-darwin Line 110 LINKFORSHARED= -Wl,-stack_size,1000000 -framework CoreFoundation $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK) LINKFORSHARED= -Wl,-stack_size,1000000 -framework CoreFoundation $(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK) – user1260486 Jan 04 '22 at 18:59

3 Answers3

7

Turns out the bug is actually in the Python Makefile, believe it or not.

Open the file

/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config

or whatever the appropriate path is for you, and search for PyMac_Error. It should be on the line defining LINKFORSHARED, and on this line you need to change PYTHONFRAMEWORKDIR to PYTHONFRAMEWORKINSTALLDIR. Then go back to your vim source and ./configure, everything should go smooth.

Also make sure you symlink OS X's Python Frameworks to the ones in the Homebrew Cellar:

/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

should all point to

/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7

Not really sure why I had it in so many places, or if that's bad, but there it is.

Adrian Ghizaru
  • 171
  • 1
  • 4
  • 1
    This issue is actually [tracked on bugs.python.org](http://bugs.python.org/issue3588) but it's not clear what the solution should be. Apparently Vim shouldn't be peeping at LINKFORSHARED in the first place. In any case, the fix above works. – Adrian Ghizaru Nov 26 '11 at 05:20
  • I'm not sure about macvim, but I got around this particular error in PythonMagick by setting an PYTHON_EXTRA_LDFLAGS variable, `./configure PYTHON_EXTRA_LDFLAGS="-u _PyMac_Error /Library/Frameworks/Python.framework/Versions/2.7/Python"`. Maybe there's a cleaner solution if you don't want to modify the system makefile. – gatoatigrado Dec 28 '14 at 06:12
  • Is there an updated version of this solution? I’m sill having a linking error but when I checked Python’s makefile it said `PYTHONFRAMEWORKINSTALLDIR`. In recent versions of macOS SIP prevents users from adding to /System/Library. I did, the problem isn’t fixed and now `make` doesn’t work and Xcode doesn’t open. My computer is really stuffed now. – yeeeeee Jul 26 '17 at 13:15
2

It's not a straight answer to your question, but installing macports and running sudo port install vim +python27 is one way to get there.

Kris Jenkins
  • 4,083
  • 30
  • 40
0

Romainl gave the accepted answer: MacVim comes with a command-line version of vim as well as the gui version - something I was not aware of - and I had already successfully compiled MacVim with Python 2.7 (without any of the problems I ran into with the standard vim sources).

Using macports or homebrew was not an option I was looking at.

N.B. if anyone can asign this answer to Romainl, please go ahead and do so. I'm only answering myself to close this one off.

Mark Gemmill
  • 5,889
  • 2
  • 27
  • 22