Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wxPython import error

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?

like image 496
Gibbs Avatar asked Feb 25 '11 19:02

Gibbs


People also ask

Is wxPython supported by Python?

wxPython is a cross-platform GUI toolkit for the Python programming language. It allows Python programmers to create programs with a robust, highly functional graphical user interface, simply and easily.

Does wxPython work with Python3?

The wxPython 4 package is compatible with both Python 2.7 and Python 3.


2 Answers

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

backend : MacOSX

like image 65
Federico Avatar answered Sep 21 '22 14:09

Federico


Select your wx version before importing any wx modules

import wxversion
wxversion.select('2.8')

The above code should come before import wx

like image 24
ravihansa3000 Avatar answered Sep 17 '22 14:09

ravihansa3000