diff --git a/doc/mock_modules.txt b/doc/mock_modules.txt
new file mode 100644
index 0000000000000000000000000000000000000000..38fdb590ebef74e0591616bc1613787fbe78cc0e
--- /dev/null
+++ b/doc/mock_modules.txt
@@ -0,0 +1,6 @@
+nibabel
+nibabel.fileslice
+numpy
+numpy.linalg
+scipy
+scipy.ndimage
diff --git a/setup.py b/setup.py
index 37848d4f041e74f671c6396cf67e2d8732192b77..51aa4ac72e2fc039f94b0fbf864453ec726fe9bf 100644
--- a/setup.py
+++ b/setup.py
@@ -69,17 +69,17 @@ class doc(Command):
         except:
             import mock
 
-        mockedModules = [
-            'nibabel',
-            'nibabel.fileslice',
-            'numpy',
-            'numpy.linalg']
-
         mockobj       = mock.MagicMock()
-        mockedModules = { m : mockobj for m in mockedModules}
+        mockobj.__version__ = '2.2.0'
+        mockedModules = open(op.join(docdir, 'mock_modules.txt')).readlines()
+        mockedModules = [l.strip()   for l in mockedModules]
+        mockedModules = {m : mockobj for m in mockedModules}
+
+        patches = [mock.patch.dict('sys.modules', **mockedModules)]
 
-        with mock.patch.dict('sys.modules', **mockedModules):
-            sphinx.main(['sphinx-build', docdir, destdir])
+        [p.start() for p in patches]
+        sphinx.main(['sphinx-build', docdir, destdir])
+        [p.stop() for p in patches]
 
 
 setup(