Python 3.5 in Canopy 2.0 - "No module named PyQt4" error


In Canopy 2.0 running Python 3.5:

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.0:

  • Quit Canopy.
  • Locate your preferences.ini file. See Where are the preference and log files located?
  • Edit your preferences.ini file to add the following two lines.
    pylab_backend = tk

    (If the preferences file already contains a [python_frontend] line, just add the pylab_backend line after it.)

  • Save the preferences.ini file.
  • Restart Canopy.

In Canopy 2.1 and above, this setting will be available in the  preferences dialog ("Python" tab).

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 %matplotlib tk


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.

Have more questions? Submit a request


Powered by Zendesk