Skip to content

Instantly share code, notes, and snippets.

@splhack
Created May 18, 2016 06:01
Show Gist options
  • Save splhack/4ec93591aec286beac496bbd5cc8d764 to your computer and use it in GitHub Desktop.
Save splhack/4ec93591aec286beac496bbd5cc8d764 to your computer and use it in GitHub Desktop.
MacVim with Python 2.x and Python 3.x
  • Install python 2.7.11

command line

$ PYTHON_CONFIGURE_OPTS="--enable-shared" \
    LDSHARED="clang -bundle" \
    LDCXXSHARED="clang++ -bundle" \
    BLDSHARED="clang -bundle -lpython2.7" \
    pyenv install 2.7.11
  • Verify python 2.7.11

command line

$ otool -L $HOME/.pyenv/versions/2.7.11/lib/python2.7/lib-dynload/_ctypes.so
/Users/foo/.pyenv/versions/2.7.11/lib/python2.7/lib-dynload/_ctypes.so:
    /Users/foo/.pyenv/versions/2.7.11/lib/libpython2.7.dylib (compatibility version 2.7.0, current version 2.7.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

libpython2.7.dylib should be included in the result.

  • Install python 3.5.1

command line

$ PYTHON_CONFIGURE_OPTS="--enable-shared" \
    LDSHARED="clang -bundle" \
    LDCXXSHARED="clang++ -bundle" \
    BLDSHARED="clang -bundle -lpython3.5m" \
    pyenv install 3.5.1
  • Verify python 3.5.1

command line

$ otool -L $HOME/.pyenv/versions/3.5.1/lib/python3.5/lib-dynload/_ctypes.cpython-35m-darwin.so
/Users/foo/.pyenv/versions/3.5.1/lib/python3.5/lib-dynload/_ctypes.cpython-35m-darwin.so:
        /Users/foo/.pyenv/versions/3.5.1/lib/libpython3.5m.dylib (compatibility version 3.5.0, current version 3.5.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

libpython3.5m.dylib should be included in the result.

  • Install MacVim with the option

command line

$ brew tap macvim-dev/macvim
$ brew install --HEAD macvim-dev/macvim/macvim --with-properly-linked-python2-python3
  • Vim settings

.vimrc

let $PYTHONHOME=$HOME."/.pyenv/versions/2.7.11"
set pythondll=$HOME/.pyenv/versions/2.7.11/lib/libpython2.7.dylib
py import sys
let $PYTHONHOME=$HOME."/.pyenv/versions/3.5.1"
set pythonthreedll=$HOME/.pyenv/versions/3.5.1/lib/libpython3.5m.dylib
py3 import sys

check

function! s:py3_test()
    py3 import time
    py3 from ctypes import *
    py3 lib = cdll.LoadLibrary("/usr/lib/libc.dylib")
    py3 print(time.ctime(lib.time(0)))
endfunction
function! s:py_test()
    py import time
    py from ctypes import *
    py lib = cdll.LoadLibrary("/usr/lib/libc.dylib")
    py print(time.ctime(lib.time(0)))
endfunction
call s:py3_test()
call s:py_test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment