- 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.
- Open the SublimeREPL settings file for Python (it doesn't need to be done from Sublime Text, but it's convenient):
- 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)
- 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)
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.- Save the file.
- Try opening the SublimeREPL for Python
- 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:
- http://stackoverflow.com/questions/10712390/directing-sublime-text-2-packages-to-the-correct-python-installation
- http://stackoverflow.com/questions/17536094/setting-python-path-for-sublimerepl-from-sublime-text
- http://stackoverflow.com/questions/22058396/import-3rd-party-module-in-sublimerepl
- http://superuser.com/a/356219
Thank you for sharing this useful info and keep it up.
ReplyDeletePython Training in Chennai
Python course in Chennai
ccna Training institute in Chennai
ccna institute in Chennai
R Training in Chennai
R Programming Training in Chennai
Python Training in Velachery
Python Training in Tambaram
ReplyDeleteI want this type of one.beacuse in recent days i searched this type of blog finally i got.thanks for this blog.
ccna Training in Chennai
Python Classes in Chennai
Angularjs Training in Chennai
ccna Training in Velachery
ccna Training in Tambaram
It's a beautiful thing to be appreciated... Keep it up, thanks for sharing.
ReplyDeleteAfter looking through a few blog articles on your website,
we sincerely appreciate the way you blogged.
Text Sublime
superb post.
ReplyDeletePython course in Pune