From 011bc75a79b141b8362d39f3cd3587a0a13bb969 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 16 Jun 2014 11:20:26 +0200 Subject: [PATCH] Make sure pkg_resources is available. --- qutebrowser/qutebrowser.py | 1 + qutebrowser/utils/earlyinit.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py index aa6387240..74a68c47a 100644 --- a/qutebrowser/qutebrowser.py +++ b/qutebrowser/qutebrowser.py @@ -87,6 +87,7 @@ def main(): log.init_log(args) earlyinit.fix_harfbuzz(args) earlyinit.check_pyqt_webkit() + earlyinit.check_pkg_resources() # We do this import late as we need to fix harfbuzz first. from qutebrowser.app import Application app = Application(args) diff --git a/qutebrowser/utils/earlyinit.py b/qutebrowser/utils/earlyinit.py index c850b068b..e5908ed0c 100644 --- a/qutebrowser/utils/earlyinit.py +++ b/qutebrowser/utils/earlyinit.py @@ -164,3 +164,36 @@ def check_pyqt_webkit(): msgbox.exec_() app.quit() sys.exit(1) + +def check_pkg_resources(): + """Check if pkg_resources is installed.""" + from PyQt5.QtWidgets import QApplication, QMessageBox + try: + import pkg_resources # pylint: disable=unused-variable + except ImportError: + app = QApplication(sys.argv) + msgbox = QMessageBox(QMessageBox.Critical, "qutebrowser: Fatal error!", + textwrap.dedent(""" + Fatal error: pkg_resources is required to run qutebrowser but could + not be imported! Maybe it's not installed? + + On Debian/Ubuntu: + apt-get install python3-pkg-resources + + On Archlinux: + pacman -S python-setuptools + + On Windows: + Run python -m ensurepip (python >= 3.4) or + scripts/ez_setup.py. + + For other distributions: + Check your package manager for similiarly named packages. + """).strip()) + if '--debug' in sys.argv: + print(file=sys.stderr) + traceback.print_exc() + msgbox.resize(msgbox.sizeHint()) + msgbox.exec_() + app.quit() + sys.exit(1)