In Canopy 2.x running Python 3:
Ask matplotlib to display a plot, or otherwise run Python code that creates a GUI window.
You get an error traceback ending with:
ImportError: No module named 'PyQt4'
Solution for most users - install the PyQt package
- Open the Canopy Package Manager
- Go to the "Available" packages tab
- Type "pyqt" in the search bar at the top of the window.
- Select the pyqt package, and click "Install".
(Note that pyqt is licensed GPL. If you work for an organization which prohibits the use of GPL software in this context, read on.)
Alternate solution - use TK
For users who are disconnected from the Internet (so cannot use the Package Manager), or are forbidden to use GPL software (so cannot use PyQt), you can use Python's built-in TK GUI toolkit. (Note that Qt is more capable, attractive, and performant than tk. Some software, such as Enthought's Chaco and Mayavi graphics packages, can not use tk.)
A) For commands and scripts run in the Canopy GUI:
In Canopy 2.1 and above:
- Open the preferences dialog
- Go to the "Python" tab
- Set your Pylab backend to "Interactive (tk)"
If you are using Canopy 2.0, thanks for being an early adopter. Please install Canopy 2.1 or above. You can keep you Canopy User Python environment or replace it, your choice, and you'll have some great new features available.
B) For commands and scripts run in ipython terminal at a command prompt:
- Start ipython with
ipython --matplotlib tk
- or start ipython, then type the magic command
Alternate solution -- static matplotlib plots
If you only need static (non-interactive) matplotlib plots (i.e. no GUI window):
- Open Canopy's Preferences dialog (in the "Edit" menu on Windows or Linux; in the "Canopy" menu on Mac).
- In the Python tab, change the PyLab backend setting to "Inline (SVG)".
- Click "OK".
- When prompted to restart kernel, click "Restart".
Please do not enter support requests in article comments
Please use article comments for suggestions to improve the article. For individual support requests, please follow these guidelines.