Friday, June 13, 2014

Sublime Text 3, SublimeREPL, and Python modules on Mac OS X 10.7

Setting:
  • Mac OS X 10.7.5
  • Sublime Text 3
  • SublimeREPL 2.1.1
Problem:
  • I have globally-installed Python modules (e.g. Pylab, Matplotlib, Scipy) that I cannot import when using SublimeREPL: "no module named pylab".  I can import pylab from Python REPL from the Terminal just fine.
  • I tried adding the path to the module, but it complains with RuntimeError:
* I noticed this is the exact Python version referred to by the asker in this StackOverflow thread

Issue:

SublimeREPL seems to have some weird default configuration (honestly, I still don't quite understand why this is so) which makes it unable to point to my PYTHONPATH correctly. For example, I don't understand why in the screenshot above it said "module compiled against API version 6 but version of numpy is 4" while I have no problem importing matplotlib when using Python REPL in the Terminal. If anyone have a good explanation what that is so, that would be very much appreciated.

Solution:

Change the path to the Python executable.
  1. Open the SublimeREPL settings file for Python (it doesn't need to be done from Sublime Text, but it's convenient):
  2. Around line 22, add the "cmd" value with the desired Python executable. The path for my system is: "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python" (from: this SO answer)
  3. The file is located in: /Users//Library/Application Support/Sublime Text 3/Packages/SublimeREPL/config/Python/Main.sublime-menu
    (Remember, this is Mac OS X 10.7.5)



  4. This is weird; if I comment out line 22: "cmd": ["python", "-i", "-u"], SublimeREPL won't launch. Both lines must be used. Again, I apologize for not having an explanation why it has to be this way.
  5. Save the file.
  6. Try opening the SublimeREPL for Python
  7. Now I was able to import all the modules I need:


    Notice how it now says "Python 2.7.6".
Hope that helps.



Resources/Similar Issues:

4 comments: