Notebook to py script issue: No module named PyQt4


I would like to be able to run all the code in a notebook in a python script. I am having problems running a python file based on a working python notebook. The notebook runs fine in the same AWS instance.

Here are the details:

I have setup aws instance as described in lessons 1. I create a python notebook and it runs without any problems.
I then convert the notebook to py script:

jupyter nbconvert --to script vgg16_hydrangea.ipynb

I try to run this script with python, but it looks like it is missing a module named PyQt4. Any suggestions? I feel like this is something very simple, but I am new to python so not sure about all the dependencies. thanks for the help.


Traceback (most recent call last):
File “”, line 16, in
from matplotlib import pyplot as plt
File “/home/ubuntu/anaconda2/lib/python2.7/site-packages/matplotlib/”, line 114, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File “/home/ubuntu/anaconda2/lib/python2.7/site-packages/matplotlib/backends/”, line 32, in pylab_setup
File “/home/ubuntu/anaconda2/lib/python2.7/site-packages/matplotlib/backends/”, line 16, in
from .backend_qt5 import QtCore
File “/home/ubuntu/anaconda2/lib/python2.7/site-packages/matplotlib/backends/”, line 31, in
from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, version
File “/home/ubuntu/anaconda2/lib/python2.7/site-packages/matplotlib/backends/”, line 137, in
from PyQt4 import QtCore, QtGui
ImportError: No module named PyQt4