5

I installed macvim with homebrew, with python support. My incantation was as follow:

brew install macvim --override-system-vim

Now when I open a python file, I get a series of errors if I try to import anything. e.g. if I import re I see ImportError: no module name re.

The first time I open macvim after installing, I get 'import site' failed; use -v for traceback in the terminal where I opened macvim. This is after running my first python command.

What does this mean and and how do I fix it?

Maus
  • 1,791
  • 1
  • 17
  • 28
  • I should note I'm trying to use brew python for easy management of extras like qt and PyQt. I know that simply using the system wide python would be a fix, but not the fix I'm looking for. – Maus Jun 22 '12 at 00:06

3 Answers3

23

I got this working with a quick hack where you temporarily point the system python to your preferred python:

cd /System/Library/Frameworks/Python.framework/Versions
sudo mv Current Current-sys
sudo mv 2.7 2.7-sys
sudo ln -s /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7 Current
sudo ln -s /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7 2.7

brew rm macvim # optionall, only if you had it installed previously  
brew install macvim --override-system-vim

sudo mv Current-sys Current
sudo mv 2.7-sys 2.7
Paweł Gościcki
  • 9,066
  • 5
  • 70
  • 81
Dean
  • 8,632
  • 6
  • 45
  • 61
  • 2
    Tried a number of other options, none of them worked, but this did! Thanks so much :) – jdg Feb 22 '13 at 06:13
  • 2
    Nice and easy hack. It could be noted that Homebrew's copy of Python should be installed first. Python version may vary. – bogeymin Jun 20 '13 at 17:14
  • 1
    Does this need to be *temporary* or can’t the “system” framework version simply always be symlinked to Homebrew’s? What problems could be expected by that approach? – Konrad Rudolph Oct 07 '13 at 15:41
  • @KonradRudolph I honestly couldn't say, but I'd worry that there'd be some system process that expects a certain version of Python and having a different version could cause subtle and hard to diagnose issues. Or if you change package managers in a couple of years and forget to change the symlink it could cost you some time. – Dean Oct 07 '13 at 18:28
  • Thank you @Dean, with a small tweak (my edit) it works even in 2015. – Paweł Gościcki Feb 21 '15 at 20:49
1

my wild guess is that you should add the homebrew install folder to your .bash_profile like this:

export PATH=/usr/local/bin:/usr/local/sbin:usr/local/Cellar/python/2.7.3/bin:$PATH

after that write in the shell "source .bash_profile" so it reloads. Also please check the output of

which python 

to make sure you are using homebrew python

Hassek
  • 8,715
  • 6
  • 47
  • 59
  • I don't think this quite does it-- if you ask vim: `:python print sys.version` it still prints 2.6.1 regardless of the path... – Maus Jun 22 '12 at 17:01
0

I ended up giving up on the homebrew option and using the answer suggested here:

vim compiles with wrong python version (and not working with needed version)

It's a shame it appears this cant be done via brew. Looks like somebody needs to patch the macvim distribution itself.

Community
  • 1
  • 1
Maus
  • 1,791
  • 1
  • 17
  • 28
  • This wasn't quite right either-- caused [this issue](http://stackoverflow.com/questions/11163126/modified-macvim-seeing-fatal-error). I found [this answer to be more stable](http://stackoverflow.com/questions/6490513/vim-failing-to-compile-with-python-on-os-x/8276426#8276426) – Maus Jun 22 '12 at 20:54