Installing Vim-Ipython With MacVim
I got really excited at the notion of having IPython built into MacVim (vim-ipython), so over the last few days I’ve spent some time mucking around trying to get this whole thing to work. Unfortunately there’s not a lot of documentation on how to fix the issues that might pop up, so hopefully this will help some people. (spoiler - MacVim download is 32 bit zeromq is 64)
First, your prerequisites. I’m assuming you’re using the awesome HomeBrew. If you’re not, you’re on your own for some of these sections.
pip install pyzmq ipython
brew install zeromq
In a shell, type:
ipython console
and leave it here.
Go into Vim.
I’m using Vim Addon Manager (VAM). It’s a fantastic tool and made working with vim 100x better. Go ahead and install vim-ipython - if you’re using VAM it’s easy. If you’re not, use whatever system you’re used to (or start using VAM).
:InstallAddons vim-ipython
If you’ve done this with VAM, the docs say you should be able to open python file and type - but when I tried that this is what I got:
:IPython
ImportError: IPython.zmq requires pyzmq >= 2.1.4
Weird you say, because you know you have it installed. Lets see what happens if we import it directly into Vim:
:py import zmq
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Python/2.7/site-packages/zmq/__init__.py", line 38, in <module>
from zmq import core, devices
File "/Library/Python/2.7/site-packages/zmq/core/__init__.py", line 26, in <module>
from zmq.core import (constants, error, message, context,
ImportError: dlopen(/Library/Python/2.7/site-packages/zmq/core/error.so, 2):
Symbol not found: _zmq_errno
Referenced from: /Library/Python/2.7/site-packages/zmq/core/error.so
Expected in: flat namespace in /Library/Python/2.7/site-packages/zmq/core/error.so
I won’t go into details here, but the short version of the story is MacVim (snapshot 64) was compiled as a 32 bit executable and it can’t read the 64 bit symbols. Bummer.
We can tell that MacVim is a 32 bit compile because of this:
haddad-pro:vim jhaddad$ file /Applications/MacVim.app/Contents/MacOS/MacVim/\
Applications/MacVim.app/
Contents/MacOS/MacVim: Mach-O executable i386
And zeromq shared library:
file /usr/local/lib/libzmq.dylib /usr/local/lib/libzmq.dylib: Mach-O 64-bit dynamically linked shared library x86_64
The solution: Use HomeBrew to compile 64 bit MacVim.
brew install macvim
You’ll run into a snag if you don’t have the old /Developer directory (I didn’t) so go ahead and fix like this
haddad-pro:vim jhaddad$ sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/
Finally, open up your 64 bit MacVim and edit a Python file. You should now be able to send lines to iPython using , and see the results if you s.
I’ll follow up with a later post on how to get the most benefit from vim-ipython.
If you found this post helpful, please consider sharing to your network. I'm also available to help you be successful with your distributed systems! Please reach out if you're interested in working with me, and I'll be happy to schedule a free one-hour consultation.