0

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??

stefanos
  • 1
  • 4
  • I'm not sure what the problem is, but changing the site-packages code seems like a bad solution to any problem affecting portability. Wouldn't it be safer to do something like `matplotlib.use('QtAgg')` in your specific code rather than changing the source code of the standard libraries? – chase Feb 07 '14 at 15:22
  • @chase fair enought but won't solve the problem. Using the above gives an error tha it is unrecognized backend. When using 'pdf' or 'GTKAgg' I get no results, while with 'gtk' i get en eroor that this call has no effect – stefanos Feb 07 '14 at 15:36

2 Answers2

1

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.

pseudocubic
  • 1,039
  • 1
  • 14
  • 20
  • for 'QTAgg' i get an error; Unrecognized backend string "qtagg". For 'QT4Agg' I have another ImportError: No module named 'sip'. I assumed that i don't have these backend installed, but how do i install them? And will matplotlib be able to see them? – stefanos Feb 07 '14 at 15:40
  • I added a link to the matplotlib backend faq which will include what should be installed to use each backend. You can install modules easily using 'pip install module' or 'easy_install module' – pseudocubic Feb 07 '14 at 15:42
  • Thanks for the advice. I've been trying for the past half an hour to install either TkInter, WXAgg, Agg but i can't get to install them after all, it's too complicated. Is there anything more straightforward? – stefanos Feb 07 '14 at 16:37
  • @stefanos if you're on linux, just use your distribution's package manager or install anaconda (http://continuum.io/downloads) – Paul H Feb 07 '14 at 16:59
0

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!

Community
  • 1
  • 1
stefanos
  • 1
  • 4