So I'm trying to configure matplotlib for Python 3.4 in SublimeText3 (Mac OSX). I installed it (via pip and also via anaconda, because I was being dumb) and I am able to use it properly in terminal (so if I import matplotlib and make a simple graph it works perfectly).
When I do it instead in SublimeText3, I get an error saying that the matplotlib module cannot be found. I'm guessing (based on googling and some common sense) that it's a path issue but I'm kind of clueless as to how to fix this.
Do I need to change my path in the build or something? When I type "which python3.4" in terminal, I get a weird directory like "/Users/my_name/anaconda/bin/python3" although I recall when I initially configured my build the path had something to do with Library/Frameworks.
I don't know. Maybe my anaconda/matplotlib installation was bad.
I'd appreciate any help - sorry if it's a really dumb question.
Also, does SublimeText3 even generate graphs? I know I can do it in terminal but I was wondering if ST3 even supports GUI (I know I had issues with user inputs earlier...)
EDIT: The code I used. Works in terminal, not at all in SublimeText3
import matplotlib.pyplot as plt
plt plot([1,2,3,4])
plt.ylabel("Some numbers")
plt.show()
The problem is occurring because you have multiple versions of Python on your computer. OS X ships with various versions of Python 2.x installed (I'm not sure if Py3 is also installed, I'm still on 10.8.5 where it is not). You have also installed the Anaconda distribution of 3.4, which is in your home directory, and likely the version from python.org as well, which is in /Library/Frameworks/Python.framework/Versions/3.4
.
To solve your problem, first we need to figure out which version of Python you want to use. In Terminal, run these two commands:
which -a python3
which -a python3.4
to see where all (the -a
switch) of the Python 3 executables in your $PATH
live. You'll then need to pick the one you want to use in Sublime (you can use more than one if you want, I'll get to that later).
Now that we have the right path, we'll make a new build system. Select Tools -> Build System -> New Build System…
, delete the contents of the file that opens up, and add the following:
{
"cmd": ["/your/path/to/python3", "-u", "$file"],
// ^^^^^^^^^^^^^^^^^^^^^
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
replacing /your/path/to/python3
(underlined) with the actual path you chose above. Save the file as Packages/User/Python3.sublime-build
, and a new Python3
entry will appear in the Tools -> Build Systems
menu. Click on it, and now you should be able to use matplotlib
in your scripts.
As far as generating graphs, yes you will be able to plot images with matplotlib
, Pillow
, etc. They'll appear as a separate window when you run the script.