From 44b77cdb857b95d1f40b0a5a1329830a8e03f630 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 15 Aug 2014 14:08:46 +0530 Subject: [PATCH] Prevent import of PyQt4 with an ImportError --- src/calibre/startup.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/calibre/startup.py b/src/calibre/startup.py index 379475fb97..0f0e769261 100644 --- a/src/calibre/startup.py +++ b/src/calibre/startup.py @@ -24,6 +24,18 @@ winutil = winutilerror = None if not _run_once: _run_once = True + # Prevent PyQt4 from being loaded + class PyQt4Ban(object): + + def find_module(self, fullname, path=None): + if fullname.startswith('PyQt4'): + return self + + def load_module(self, fullname): + raise ImportError('Importing PyQt4 is not allowed as calibre uses PyQt5') + + sys.meta_path.insert(0, PyQt4Ban()) + # # Platform specific modules if iswindows: