Reputation: 16212
I installed matplotlib successfully inside a virtualenv. Now I'm trying to get it to draw. I know how to change the backend, but I'm having a whole lot of trouble figuring out what to change it to.
Has anyone managed to get it totally working with python3? If yes, how?
I have tried a bunch of things. I have cycled through all the backends to see what all of the complaints are, not I'm trying to get just one of them to work.
Also possibly worth noting is that my goal is to integrate it into a Pyramid app.
Here's what has happened so far for all the different backends:
The script I am using to test my backend is:
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.show()
So far I have spent waaay too much time trying to get python3.2 and qt4 playing nice, and I just seem to be running into problems every way I turn. So instead of continuing with my trial and error approach I want to ask:
In the meantime I will continue with the trial-and-error thing and update my question as I go.
NOTES on stuff I'm trying
For TkAgg:
since tkinter imports correctly I'm assuming it's installed correctly (if I'm wrong I suppose there's a way to test it?). This guy http://ask.sagemath.org/question/626/sage-python-import-matplotlib-no-module-named had a similar problem but Im sure his setup is different from mine. The solution was to find tkagg.py in the bowels of the python3.2 site packages directory and edit the offending import statement. I find it hard to believe that matplotlib ships broken (and I cant run the modified code suggested...)
For WX stuff:
wxPython for Python 3 says there is no support for python3 yet. Also wxPython has no mention of python3 on their site so I guess that's a no-go. running out of options :/
Cocoa:
Ditto: Writing Cocoa applications in Python 3
EMF:
ditto: http://pyemf.sourceforge.net/README.html
Upvotes: 24
Views: 10536
Reputation: 1
For me, the following worked:
sudo apt-get install python3-matplotlib libfreetype6-dev
pip install numpy matplotlib
(maybe uninstall and then install if you already have it, or maybe try creating a new venv at this point)pip install --upgrade pip
inside venv might also help (for some reason unknown to me), as it did with my installing scipy.It now plots using virtualenv.
$ lsb_release -a (gives..)
Ubuntu 14.04.5 LTS
Upvotes: 0
Reputation: 7093
I wrote an answer for ensuring matplotlib
in a Python 3 virtualenv in Ubuntu 16.04 uses the TkAgg
backend at https://askubuntu.com/a/785506/15003 that can be useful here. The upshot is to install tk-dev
, activate the virtualenv and reinstall matplotlib
in the virtualenv:
sudo apt install tk-dev
source venv/bin/activate
pip --no-cache-dir install -U --force-reinstall matplotlib
python -c 'import matplotlib as mpl; print(mpl.get_backend())'
should now say TkAgg
.
Upvotes: 0
Reputation: 3109
I have been doing source builds of python 3.3.2 and matplotlib. As noted above, TkAgg works. If you are building everything from source:
Finally got to see that silly box pop up wit my x=y line.
hours....
Upvotes: 2
Reputation: 2978
I ran into exact same issue, but after much efforts I managed to make TkAgg working (which was giving the import error for _tkagg). Little late, but someone might find it useful.
FWIW I resolved the issue as follows (to use TkAgg):
tk-dev
from package managerpython3-tk
from package managermatplotlib
from sourceIf you think you have tk-dev
and python3-tk
installed correctly, you need to rebuild and reinstall matplotlib, so that it generates _tkagg.py
in your backends
directory.
I'm using Python3.3 (numpy 1.7) on LM14. But I think it should work on Ubuntu/Python3.2
Upvotes: 15
Reputation: 2615
Matplotlib seems to have taken a large step towards Python 3 with their 1.2.x release. matplotlib 1.2.0rc2 (+ numpy 1.7.0b2) is working for me with
In both cases, matplotlib reports "TkAgg" as the backend used.
Unfortunately, I have no clue if/how this might work with Pyramid.
Upvotes: 1