3

I have completely installed and re-installed matplotlib 3 times, 3 different ways. If I open idle, it will let me add import matplotlib, but as soon as I try to run sample code from the matplotlib website, I get errors, always when using the convention:

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.path import Path
from matplotlib.spines import Spine
from matplotlib.projections.polar import PolarAxes
from matplotlib.projections import register_projection

From the statement it can be anything. The only thing that follows is an errors saying

ImportError: No module named backends.backend_wxagg

Anon@TBCC-DELL-Mobile1:/home/tjohnson/python# python matplotlib.py
Traceback (most recent call last):
  File "matplotlib.py", line 16, in <module>
    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
  File "/home/tjohnson/python/matplotlib.py", line 16, in <module>
    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
ImportError: No module named backends.backend_wxagg

Anon@TBCC-DELL-Mobile1:/home/tjohnson/python# python radar_chart.py
Traceback (most recent call last):
  File "radar_chart.py", line 14, in <module>
    import matplotlib.pyplot as plt
  File "/home/tjohnson/python/matplotlib.py", line 16, in <module>
    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
ImportError: No module named backends.backend_wxagg

I have tried with several different versions of matplotlib and still same result. Suggestions?

t gillespie
  • 123
  • 1
  • 6
  • run the code in the anaconda enviroment and all goes without a hitch... so what sis i do wrong? – t gillespie Mar 13 '15 at 00:51
  • It is often cleaner and safer to run in a virtual environment such as anaconda. Is there a strong reason not to run in anaconda? – Steven C. Howell Mar 13 '15 at 00:57
  • yup, no wxpython in anaconda :) and really if i wanna run it in a jar better to run it in the jar it will go in later, like qemu -> Raspberry Pi :) or in a scrappable container like virtual box i suppose. – t gillespie Mar 13 '15 at 01:56
  • You could try Enthought Canopy as another great virtual python environment (https://www.enthought.com/products/canopy/). They have a built in package manager and great support. This link has info about using wxpython with Canopy: https://support.enthought.com/entries/22601196-wxPython-2-8-and-2-9 – Steven C. Howell Mar 13 '15 at 02:11
  • What do you mean when you say "open idle"? How are you running python? You may want to check the python you are running is the same one you are installing matplotlib to. – Steven C. Howell Mar 13 '15 at 13:46
  • i have python 2.7 and python 3, normally i run python from the terminal program, some bash derivitive. but to do simple checks i use idle. if i can import the libaray then i would assume that it is installed to the python i am using correct? – t gillespie Mar 14 '15 at 07:51

5 Answers5

1

It sounds like there is a conflict related to the system python installation. Perhaps the system python does not see the matplotlib installation. You may also want to check the permissions of the installed files. What operating system are you running and what method are you using for installing matplotlib (pip, apt-get, setup.py, building binaries)?

Try opening a python shell and simply importing matplotlib:

>>> import matplotlib as mpl
Steven C. Howell
  • 16,902
  • 15
  • 72
  • 97
  • first i installed apt-get, then undo apt-get then pip then undo pip then finally i compiled it from source, no change. I am on Debian stable (wheezy i do believe) where are the files i should check the permissions of? becasue at this point i probably have 20 folders for matplotlib ;) i aint uninstalling python... because i will be here all night putting my computer back together if i do, something like 450 dependencies on python 2.7 it will let me import matplotlib both in console and in script but after that ... no dice. been the same all night. – t gillespie Mar 13 '15 at 01:54
  • In the situation you are in, figuring things out, I would strongly recommend using a virtual environment such as anaconda. It enables you to keep your system python separate from the development one. – Steven C. Howell Mar 13 '15 at 01:58
  • 1
    If you were able to run `import matplotlib as mpl`, you can then run `mpl.__path__` to see where it actually imported it from. Then you can navigate to that directory (using a standard bash shell) and check the permissions using `ls -l`. Most of the `*.py` files in my matplotlib directory have `-rw-r--r-- 1 root root` for permissions and ownership. If it is not at least `r` for all three, that would definitely be a clear problem. – Steven C. Howell Mar 13 '15 at 02:05
1

In openSuse, the backend_wxagg ImportError was solved with

zypper in python2-matplotlib-wx

Depending on your system it can be another package_manager (apt, yum, etc.).

1

I got this problem trying running Ardupilot SiTL on Fedora. As Friedrich suggested, running sudo dnf install python3-matplotlib-wx resolved the issue.

0

I had the same problem. First I checked out the import sys sys.path to see what are the folders that it searches for the installed packages.

my result was something like this.

['',
 'C:\\Users\\gsotiropoulos\\AppData\\Local\\conda\\conda\\envs\\py36\\python36.zip',
 'C:\\Users\\gsotiropoulos\\AppData\\Local\\conda\\conda\\envs\\py36\\DLLs',
 'C:\\Users\\gsotiropoulos\\AppData\\Local\\conda\\conda\\envs\\py36\\lib',
 'C:\\Users\\gsotiropoulos\\AppData\\Local\\conda\\conda\\envs\\py36',
 'C:\\Users\\gsotiropoulos\\AppData\\Roaming\\Python\\Python36\\site-packages',
 'C:\\Users\\gsotiropoulos\\AppData\\Local\\conda\\conda\\envs\\py36\\lib\\site-packages',
 'C:\\Users\\gsotiropoulos\\AppData\\Local\\conda\\conda\\envs\\py36\\lib\\site-packages\\win32',
 'C:\\Users\\gsotiropoulos\\AppData\\Local\\conda\\conda\\envs\\py36\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\gsotiropoulos\\AppData\\Local\\conda\\conda\\envs\\py36\\lib\\site-packages\\Pythonwin',
 'C:\\Users\\gsotiropoulos\\AppData\\Local\\conda\\conda\\envs\\py36\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\gsotiropoulos\\.ipython']

then as suggested I import matplotlib as mpl and mpl.__path__ seeing that I import matplotlib from the folder 'C:\\Users\\gsotiropoulos\\AppData\\Roaming\\Python\\Python36\\site-packages' Which is not the one from anaconda and it is older. I am not sure if it would be better to just remove this folder completely.

However, as I understand, python first searched there and found a matplotlib package which was outdated. I simply changed the name of the `matplotlib' to something like 'matplotlib_test' and then the library is installed from one of the anaconda folders and the problem is solved.

I wonder if I should delete the "roaming" folder to avoid similar other problems.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
George Sotiropoulos
  • 1,864
  • 1
  • 22
  • 32
0

This backend has been removed from matplotlib. I don't know of a workaround.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574