Python and Homebrew Vim


On my Mac, I use MacVim with homebrew for most of my editing.

~|⇒ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jun 20 2012 13:16:02)
Compiled by
Normal version without GUI.  Features included (+) or not (-):
-arabic +autocmd -balloon_eval -browse +builtin_terms +byte_offset +cindent
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
-conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs
-dnd -ebcdic -emacs_tags +eval +ex_extra +extra_search -farsi +file_in_path
+find_in_path +float +folding -footer +fork() -gettext -hangul_input +iconv
+insert_expand +jumplist -keymap -langmap +libcall +linebreak +lispindent
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape
-mouse_dec -mouse_gpm -mouse_jsbterm -mouse_netterm -mouse_sysmouse
+mouse_xterm +multi_byte +multi_lang -mzscheme +netbeans_intg -osfiletype
+path_extra -perl +persistent_undo +postscript +printer -profile +python/dyn
-python3 +quickfix +reltime -rightleft +ruby/dyn +scrollbind +signs
+smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
 -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
 -xterm_clipboard -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -D_FORTIFY_SOURCE=0 -Iproto -DHAVE_CONFIG_H -arch i386 -arch x86_64 -g -Os -pipe
Linking: gcc -arch i386 -arch x86_64 -o vim -lncurses

However, over the last few days, I am having a weird problem. When I start vim from the command line, I get the following message and vim immediately crashes.

~|⇒ vim test.txt
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/", line 74, in <module>
  File "/usr/local/lib/python2.7/site-packages/", line 34, in __boot
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 563, in <module>
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 545, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 278, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 253, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 243, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 472, in get_config_var
    return get_config_vars().get(name)
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 405, in get_config_vars
    import re
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 105, in <module>
    import sre_compile
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 14, in <module>
    import sre_parse
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 17, in <module>
    from sre_constants import *
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 18, in <module>
    from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT

But when I start it using the icon in the Applications menu, it starts up just fine. I tried some variants on this, for example if I do open Applications/MacVim, this runs perfectly. As far as I understand it, something goes wrong python when I start vim from the command line.

Could someone tell me what is going wrong here and how to fix it. You can find my vimrc files here.

5/18/2013 7:17:59 PM

Accepted Answer

No. This thing is not Vim or MacVim installed with Homebrew: it is the default Vim that comes with Mac OS X.

The default Vim has been sucking in a number of ways for quite a long time, chiefly -xterm-clipboard, and that's the main reason why people usually install a "proper" Vim. Installing MacVim doesn't replace the default Vim at all so you must do a small bit of tinkering to make the vim command execute MacVim's bundled CLI executable:

  1. Place the mvim script somewhere in your $PATH.

  2. Add the line below to your shell's *rc:

    alias vim='mvim -v'

But you use Homebrew and I have no idea if it does anything with that mvim script or even if it is installed at all.

If you want to use Homebrew's Vim/MacVim in your shell you basically have two solutions.

  • Make sure the vim command points to your fancy Vim. It can be done in a multitude of ways: one way is to add the directory where your Vim is installed to the beginning of your $PATH, another way is simply to create an alias in your shell's *rc file.

  • Reinstall Vim or MacVim via Homebrew with the override-system-vi option.

5/18/2013 8:15:37 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow