From 4742848a1bdd1c1529de4bcf92d55f808ed3698d Mon Sep 17 00:00:00 2001 From: "John T. Sexton" Date: Fri, 19 Jun 2020 13:47:34 -0500 Subject: [PATCH] More gracefully handle openpyxl/pandas dependencies. --- FlowCal/excel_ui.py | 6 ++++++ doc/getting_started/install_python.rst | 2 +- requirements.txt | 2 +- setup.py | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/FlowCal/excel_ui.py b/FlowCal/excel_ui.py index 487ccc9..09de4f7 100644 --- a/FlowCal/excel_ui.py +++ b/FlowCal/excel_ui.py @@ -177,6 +177,12 @@ def read_table(filename, sheetname, index_col=None, engine=None): # version < 0.25.0), try xlrd read_excel_kwargs['engine'] = 'xlrd' table = pd.read_excel(**read_excel_kwargs) + except ImportError: + # pandas recognizes openpyxl but encountered an ImportError, try + # xlrd. Possible scenarios: openpyxl version is less than what + # pandas requires, openpyxl is missing (shouldn't happen) + read_excel_kwargs['engine'] = 'xlrd' + table = pd.read_excel(**read_excel_kwargs) except openpyxl.utils.exceptions.InvalidFileException: # unsupported file type (e.g. .xls), try xlrd # diff --git a/doc/getting_started/install_python.rst b/doc/getting_started/install_python.rst index 7938174..5e94507 100644 --- a/doc/getting_started/install_python.rst +++ b/doc/getting_started/install_python.rst @@ -18,7 +18,7 @@ Alternatively, download ``FlowCal`` from `here =0.16.0) * ``pandas`` (>=0.16.1) * ``xlrd`` (>=0.9.2) -* ``openpyxl`` (>=2.4.1) +* ``openpyxl`` (>=2.2.0) If you have ``pip``, a ``requirements.txt`` file is provided, such that the required packages can be installed by running:: diff --git a/requirements.txt b/requirements.txt index 484fe42..39b357f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,4 @@ scikit-image>=0.10.0 scikit-learn>=0.16.0 pandas>=0.16.1 xlrd>=0.9.2 -openpyxl>=2.4.1 +openpyxl>=2.2.0 diff --git a/setup.py b/setup.py index 8268030..be8375c 100644 --- a/setup.py +++ b/setup.py @@ -94,7 +94,7 @@ def find_version(file_path): 'scikit-learn>=0.16.0', 'pandas>=0.16.1', 'xlrd>=0.9.2', - 'openpyxl>=2.4.1'], + 'openpyxl>=2.2.0'], # List additional groups of dependencies here (e.g. development # dependencies). You can install these using the following syntax,