Question

I'm using python3.3.3 and i have installed manually scipy 0.13.3, matplotlib 1.3.1 , numpy 1.8.0 (downloaded from sourgeforge and building them like $sudo python3 setup.py or whatever the readme file tells me to do). I'm using Linux Mint Maya 13.04 64bit with KDE 4.8.5

when i'm running:

$ python3
Python 3.3.3 (default, Jan 27 2014, 12:55:04) 
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pylab as pl
>>> pl.figure(figsize=(8, 6), dpi=80)
<matplotlib.figure.Figure object at 0x7f2025397450>
>>> pl.show()
>>> 

I get nothing. I googled it and it seems there is a problem with the backend. So i go to the file

/usr/local/lib/python3.3/site-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg/matplotlib/mpl-data/matplotlibrc

find the line

backend : agg

and change agg to either TkAgg, WXAgg, GTKAgg, PS, PDF ect.

For PS, PDF, i get no results either. If i use the TkAgg ect, i get errors when importing the pylab i.e.

>>> import pylab as pl
Traceback (most recent call last):                                                                                                                                                                                                 
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.3/site-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/usr/local/lib/python3.3/site-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg/matplotlib/pylab.py", line 269, in <module>
   from matplotlib.pyplot import *
  File "/usr/local/lib/python3.3/site-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg/matplotlib/pyplot.py", line 98, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
   File "/usr/local/lib/python3.3/site-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg/matplotlib/backends/__init__.py", line 28, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/usr/local/lib/python3.3/site-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg/matplotlib/backends/backend_tkagg.py", line 8, in     <module>
    import tkinter as Tk, tkinter.filedialog
  File "/usr/local/lib/python3.3/tkinter/__init__.py", line 40, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'
>>> 

I should tell that i have no problems on Python 2.7. Also, i tried installing python3 and the other packages from the package manager but that wouldn't work (i.e. i couldnt import scipy).

Any ideas??

Was it helpful?

Solution 2

Ok, i reached a solution following these directions How to configure PyQt4 for Python 3 in Ubuntu?

I don't know if the rest of the stuff i did were necessery, but this is the way i did it. First i uninstalled python3.3 manually using

rm -r /usr/local/lib/python3.3
rm -r /usr/local/bin/python3*

Then installed python3, python3-dev, python3-numpy, python3-scipy, python3-pyqt4 using Synaptic. Also, downloaded and compiled matplotlib (using the directions from the readme file). In the end, i used the above response in stackexchange to install the PyQT4 (as you can see i had already installed it from synaptic, SIP also but it didn't work).

Finnaly i had to change the backend to use the Qt4Agg, so i found the file:

/usr/local/lib/python3.3/site-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg/matplotlib/mpl-data/matplotlibrc

found the line of the backend and changed it from agg to Qt4Agg

# backend : agg
backend : Qt4Agg

and now i have no problem with the plots

(Or i could do use the as suggested matplotlib.use('Qt4Agg'))

Thanks for the help!

OTHER TIPS

A lot of those backends won't produce gui graphics with pl.show(), like agg, ps, and pdf, they are meant for producing files. Others you are trying to use aren't appropriate for your system because you don't have them installed. For example, for TkAgg you should have TkInter installed. See this matplotlib backend FAQ for more information. Since you're using KDE, you probably want to use 'Qt4Agg' but it depends on what you have installed on your system. Changing the matplotlibrc file is one way to change the backend permanently, but you can also use the following to change it on the fly, which is useful if for instance you want to produce files instead of gui:

import matplotlib
matplotlib.use('Qt4Agg')

You should call this before you import other matplotlib modules.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top