Matplotlib - Python Error - python

Setup:
Processor : x86_64
Operating System: GNU/Linux
Distro: Fedora Release 13 (Goddard).
Python 2.6.4
/usr/bin/python
Here is the following issue:
I am trying to generate a few graphs using Matplotlib and Python. As I hear from a majority of the solutions3.. there seem to be compatibility issues between matplotlib and 64bit architectures.
I have installed Matplotlib from here
Here is the error that I get:
Traceback (most recent call last):
File "plot-thread-characterization.py", line 24, in <module>
import matplotlib.pyplot as plt
File "/usr/lib64/python2.6/site-packages/matplotlib/pyplot.py", line 78, in <module>
new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py", line 8, in <module>
import gtk; gdk = gtk.gdk
File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>
_init()
File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init
_gtk.init_check()
RuntimeError: could not open display
Thanks.

matplotlib is failing to connect to any X server for its GTK display.
There are a couple of options here:
Run a local X server and enable X11 forwarding in your ssh client, to display the output on your local machine. You can verify this is working by checking that the $DISPLAY environment variable is set on the server.
Call matplotlib.use(...) to specify a different display back-end, for example rendering to pdf file, before importing pyplot, e.g.
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
See http://matplotlib.org/faq/howto_faq.html#generate-images-without-having-a-window-appear for more details.

Related

build is successful but code doesn't work, throwing ImportError

My issue is little different from existing ones on the WEB. Let me try highlighting it in detail. I have this code to do some plotting by reading a .txt file specified. I was going to build it as usually as I did before. My setup.py is supposed to do the job. The content of setup.py is here
As you can observe I have no any package related to tkinter in both my above files. I did python setup.py build in terminal and it executed well. But can't use my actual code with windows command script
build\\exe.win-amd64-3.5\\draw_precision_recall_curve.exe D:\dataset\Fire_Smoke\Train\filelist.txt
pause
It throws this trace:
Traceback (most recent call last):
File "C:\python354\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\python354\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "draw_precision_recall_curve.py", line 3, in <module>
import matplotlib.pyplot as plt
File "C:\python354\lib\site-packages\matplotlib\pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "C:\python354\lib\site-packages\matplotlib\backends\__init__.py", line 62, in pylab_setup
[backend_name], 0)
File "C:\python354\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 4, in <module>
from . import tkagg # Paint image to Tk photo blitter extension.
File "C:\python354\lib\site-packages\matplotlib\backends\tkagg.py", line 5, in <module>
from six.moves import tkinter as Tk
File "C:\python354\lib\site-packages\six.py", line 92, in __get__
result = self._resolve()
File "C:\python354\lib\site-packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "C:\python354\lib\site-packages\six.py", line 82, in _import_module
__import__(name)
ImportError: No module named 'tkinter'
I was not able to solve this looking at the related posts here and there.
Any help is appreciated.
You may not be using tkinter, but you are using matplotlib, and it uses tkinter.
In fact, matplotlib gives you a choice of backends. But IIRC, the default is tkinter (or maybe TkAgg, which uses tkinter) on Windows if you haven't installed the optional Win32 native backend installed, and always on non-Mac Unix.
So:
If you're only using matplotlib non-graphically—e.g., to generate files to save—specify a non-interactive backend explicitly.
If you're using it to display graphs, you either need to bundle tkinter in your app, or pick a different interactive backend and bundle that in your app.
For example, let's say you just want to generate a bunch of graphs as PNG files. Instead of doing that through the default TkAgg backend, you can use the AGG non-interactive backend, like this:
import matplotlib
matplotlib.use('AGG')
import matplotlib.pyplot as plt

Python new ImportError in matplotlib : cannot import name _string_to_bool [duplicate]

I am using pycharm for python in windows 8. I have installed the package matplotlib.
I am using python 2.7
when i do import matplotlib there is no error.
However if i do matplotlib.pyplot as plt i am getting this following errors:
Traceback (most recent call last):
File "C:/Users/PiyushSudip/PycharmProjects/myFirst/test1.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 23, in <module>
from matplotlib.figure import Figure, figaspect
File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 18, in <module>
from axes import Axes, SubplotBase, subplot_class_factory
File "C:\Python27\lib\site-packages\matplotlib\axes\__init__.py", line 4, in <module>
from ._subplots import *
File "C:\Python27\lib\site-packages\matplotlib\axes\_subplots.py", line 10, in <module>
from matplotlib.axes._axes import Axes
File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 18, in <module>
from matplotlib.cbook import _string_to_bool, mplDeprecation
ImportError: cannot import name _string_to_bool
can anyone help figure out what i am doing wrong?
http://matplotlib.org/users/installing.html#required-dependencies
There is a package called six which matplotlib depends on. Check to make sure it's installed, or install it from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#six
This site has packaged versions of many python modules which are easy to setup on windows, just download and run.
Also check the other dependencies to make sure you have them all, otherwise you might get another error for a different module

Importing matplotlib in Spyder (OSX 10.6)

When importing matplotlib in Spyder I get the following:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/Spyder-Py2.app/Contents/Resources/lib/python2.7/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/Applications/Spyder-Py2.app/Contents/Resources/lib/python2.7/matplotlib/colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "/Applications/Spyder-Py2.app/Contents/Resources/lib/python2.7/matplotlib/collections.py", line 27, in <module>
import matplotlib.backend_bases as backend_bases
File "/Applications/Spyder-Py2.app/Contents/Resources/lib/python2.7/matplotlib/backend_bases.py", line 56, in <module>
import matplotlib.textpath as textpath
File "/Applications/Spyder-Py2.app/Contents/Resources/lib/python2.7/matplotlib/textpath.py", line 19, in <module>
import matplotlib.font_manager as font_manager
File "/Applications/Spyder-Py2.app/Contents/Resources/lib/python2.7/matplotlib/font_manager.py", line 57, in <module>
from matplotlib import ft2font
ImportError: dlopen(/Applications/Spyder-Py2.app/Contents/Resources/lib/python2.7/matplotlib/ft2font.so, 2): Symbol not found: _inflateReset2
Referenced from: /Applications/Spyder-Py2.app/Contents/MacOS/../Frameworks/libpng16.16.dylib
Expected in: /usr/lib/libz.1.dylib
in /Applications/Spyder-Py2.app/Contents/MacOS/../Frameworks/libpng16.16.dylib
What can I do? I really don't get it. I run under mac OSX 10.6
(Spyder dev here) The problem lies in some changes done by the Matplotlib team some time ago that made for us harder to support Mac OSX 10.6.
To do it, we would need to include our own version of zlib in our Mac app, and compile every package against it, something I considered too much work and a potential cause of bugs.
That's why I changed the minimal required version of our app to be 10.7, as can be seen in our documentation site.

Python 2.5.... MatPlotLib doesn't install PyLab

I have NumPy and SciPy installed and working. I'm using Python 2.5 (MIT Intro to Programming course) so I've been installing the packages with .exe files instead of Pip or Anaconda. With MatPlotLib, I get the following errors during installation:
could not create: matplotlib-py2.5
could not create: python 2.5 matplotlib-1.0.0
could not set key value: "C:\Python25\Removematplotlib.exe" -u "C:\Python25\matplotlib-wininst.log"
I have a MatPlotLib folder in Python's Lib/site-packages directory. Importing matplotlib into IDLE works fine. But when I try to import pylab:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import pylab
File "C:\Python25\Lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Python25\Lib\site-packages\matplotlib\pylab.py", line 216, in <module>
from matplotlib import mpl # pulls in most modules
File "C:\Python25\Lib\site-packages\matplotlib\mpl.py", line 1, in <module>
from matplotlib import artist
File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 6, in <module>
from transforms import Bbox, IdentityTransform, TransformedBbox, TransformedPath
File "C:\Python25\Lib\site-packages\matplotlib\transforms.py", line 34, in <module>
from matplotlib._path import affine_transform
ImportError: DLL load failed: The specified module could not be found.
I've looked around on different message boards but can't find anyone else with this issue.
Any ideas?

Problem importing pylab in Ubuntu 8.1

I have installed numpy1.3,scipy 0.7.1,matplotlib 0.99.1.1 and python 2.5
when I import pylab I get the following error. Someone please help.
/var/lib/python-support/python2.5/gtk-2.0/gtk/__init__.py:72: GtkWarning: could not open display
warnings.warn(str(e), _gtk.Warning)
/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py:44: GtkWarning: gdk_cursor_new_for_display: assertion `GDK_IS_DISPLAY (display)' failed
cursors.MOVE : gdk.Cursor(gdk.FLEUR),
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/usr/lib/python2.5/site-packages/matplotlib/pylab.py", line 247, in <module>
from matplotlib.pyplot import *
File "/usr/lib/python2.5/site-packages/matplotlib/pyplot.py", line 78, in <module>
new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/usr/lib/python2.5/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py", line 44, in <module>
cursors.MOVE : gdk.Cursor(gdk.FLEUR),
RuntimeError: could not create GdkCursor object
try using a different backend for plotting than Gtk.
Open the python console and type:
>>> import matplotlib
>>> matplotlib.matplotlib_fname()
This will print a file name. Edit this file and modify the section 'Backend' and change Gtk or GtkAgg with any other (see the documentation in the same file), until you get it working.
You can find more information about backends here.
As for why you get an error when you try to use that backend, it depends on how you have installed the libraries and what you have installed on your computer. I would recommend to install matplotlib with synaptic/yum and selecting all optional dependencies.

Categories

Resources