12

I'm having trouble figuring out an error message in Python.

yesterday, I've installed python using the latest EPD package, and wxPython2.9 using the wxPython2.9-osx-cocoa-py2.7 package for Mac OS. I then added wx to my PYTHONPATH.

export WXDIR=/usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages/wx-2.9.1-osx_cocoa
export PYTHONPATH=$WXDIR
export PYTHONPATH=$PYTHONPATH:$WXDIR/tools

but when I try to run stuff I get this error:

In [14]: import matplotlib.pyplot
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)

/Users/imrisofer/Documents/third/hddm-read-only/hddm/<ipython console> in <module>()

/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
     93 
     94 from matplotlib.backends import pylab_setup
---> 95 new_figure_manager, draw_if_interactive, show = pylab_setup()
     96 
     97 @docstring.copy_dedent(Artist.findobj)

/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/__init__.py in pylab_setup()
     23         backend_name = 'matplotlib.backends.%s'%backend_name.lower()
     24     backend_mod = __import__(backend_name,
---> 25                              globals(),locals(),[backend_name])
     26 
     27     # Things we pull in from all backends


/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/backend_wxagg.py in <module>()
     21 
     22 from backend_agg import FigureCanvasAgg
---> 23 import backend_wx    # already uses wxversion.ensureMinimal('2.8')
     24 from backend_wx import FigureManager, FigureManagerWx, FigureCanvasWx, \
     25     FigureFrameWx, DEBUG_MSG, NavigationToolbar2Wx, error_msg_wx, \

/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/backend_wx.py in <module>()
     43         import wxversion
     44     except ImportError:
---> 45         raise ImportError(missingwx)
     46 
     47     # Some early versions of wxversion lack AlreadyImportedError.


ImportError: Matplotlib backend_wx and backend_wxagg require wxPython >=2.8

I can successfully import wx, so I don't no what's the problem. Am I missing anything in the PYTHONPATH?

10 Answers 10

15

In Ubuntu 12.04, this problem can be solved by running the command

sudo apt-get install libjpeg62

I realize this may not be useful here, but I wanted to document it somewhere on teh interwebz so I can find it when I run into this problem again myself which will undoubtedly happen.

Sign up to request clarification or add additional context in comments.

2 Comments

problem encountered on 12.04 with EPD 7.3 and solved by the above. well done @Chad
I've actually switched to Fedora and encountered similar problems with libpng... The EPD error description consistently does a good job of explaining what package (or lack of package) is causing the problem.
5

I'm using Ubuntu 13.10, Canopy 1.2, and PyCharm 3.0.2. When trying to use matlablib, it always complains "Matplotlib backend_wx and backend_wxagg require wxPython >=2.8".Pretty sure that I'm using wxPython 2.8. Then I tried all the methods described in this page, but neither of them works for me.

It turns out that it can be solved by modifying matplotlibrc file. There is a line:

backend : WXAgg

In fact we can change the backend to whatever we like, and I change it to TKAgg, which works just fine for me.

3 Comments

Can you elaborate on this solution? I also have Ubuntu 13.10 and have the error: ImportError: Matplotlib backend_wx and backend_wxagg require wxPython >=2.8. According to Canopy I have wxPython 2.8.10.1-3 installed. Note: The code I was executing was working when I had the same version of Enthought installed on Ubuntu 12.04. Note: I also found this support message about the error: support.enthought.com/entries/22601196-wxPython
Ah do you mean the following file: /home/YOU/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc? This appears to be working so far. Are there any other issues I might experience due to switching the backend?
Hi alexgophermix, I haven't experienced other issues so far.
4

Select your wx version before importing any wx modules

import wxversion
wxversion.select('2.8')

The above code should come before import wx

Comments

4

This happened to me on a Windows x64 installation that did not install wxversion.py in the site-packages directory (c:\Python27\Lib\site-packages by default).

You can get a copy of wxversion.py from the WX svn repository: http://svn.wxwidgets.org/viewvc/wx/wxPython/trunk/wxversion/wxversion.py?content-type=text%2Fplain&view=co

Comments

2

this link helped me https://support.enthought.com/entries/22601196-wxPython-2-8-and-2-9

Here's how I fixed the problem, which I hope will be useful for others in future

  1. In Terminal: gedit Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc

  2. Edit the line "backend : WXAgg" into "backend : QtAgg"

  3. Save and exit

1 Comment

Yeap, it seems that QtAgg backend for matplotlib exists
1

I just ran into this myself. One potential cause of this (quite unhelpful) error message is if you installed wx as a single-version installation (INSTALL_MULTIVERSION=0 when running setup.py). In this case, the module wxversion does not get built (or installed) and as such matplotlib incorrectly assumes that all of wx is missing.

This currently is the default setting in installations by the homebrew version of wxWidgets (wxmac) with the option --python.

In your case (albeit a year and a half late), you'd need to ensure that wxversion.py exists within /usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages/. If it doesn't, you'd need to recompile wx with the above flag set. Otherwise you just need to set your $PYTHONPATH such that it includes the base site-packages directory, too:

export WXDIR=/usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages
export PYTHONPATH=$WXDIR:$WXDIR/wx-2.9.1-osx_cocoa:$WXDIR/wx-2.9.1-osx_cocoa/tools

1 Comment

To have homebrew install wxpython with the multiversion support turned on . You can run command brew edit wxwidgets . Then edit the line where it says INSTALL_MULTIVERSION=0 to INSTALL_MULTIVERSION=1 . Then save the recipe and proceed with the install.
1

I've solved with this:

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

Comments

1

I solved this by setting the backend to MacOSX in ~/.matplotlib/matplotlibrc:

backend : MacOSX

Comments

0

I've solved this on Windows by looking in the site packages folder in the python library. In there, there should be another folder titled site-packages. In this subfolder, there is the wxversion library. If you copy this library into the Lib folder in python, this import error should be averted.

Comments

0
sudo apt-get install python-wxtools

Install it. Worked for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.