BUG: ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
See original GitHub issueI am running the following code from Jupyter notebook.
dataDir = r'D:\\'
files = glob(os.path.join(dataDir, '*.xlsx'))
print(files)
if os.path.isfile(files[0]):
print('ok')
df = pd.read_excel(files[0], engine='openpyxl')
which prints:
['D:\\\\file_index_all.xlsx', 'D:\\\\file_index_all2.xlsx']
ok
But I get the following error.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-52-5dc0ef3ce47b> in <module>
6 if os.path.isfile(files[0]):
7 print('ok')
----> 8 df = pd.read_excel(files[0], engine='openpyxl')
c:\users\ranab\miniconda3\lib\site-packages\pandas\io\excel\_base.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, verbose, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, **kwds)
302
303 if not isinstance(io, ExcelFile):
--> 304 io = ExcelFile(io, engine=engine)
305 elif engine and engine != io.engine:
306 raise ValueError(
c:\users\ranab\miniconda3\lib\site-packages\pandas\io\excel\_base.py in __init__(self, io, engine)
819 self._io = stringify_path(io)
820
--> 821 self._reader = self._engines[engine](self._io)
822
823 def __fspath__(self):
c:\users\ranab\miniconda3\lib\site-packages\pandas\io\excel\_openpyxl.py in __init__(self, filepath_or_buffer)
482 Object to be parsed.
483 """
--> 484 import_optional_dependency("openpyxl")
485 super().__init__(filepath_or_buffer)
486
c:\users\ranab\miniconda3\lib\site-packages\pandas\compat\_optional.py in import_optional_dependency(name, extra, raise_on_missing, on_version)
90 except ImportError:
91 if raise_on_missing:
---> 92 raise ImportError(msg) from None
93 else:
94 return None
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
pandas version:
pd.__version__
1.0.1
Also one other thing I noticed despite having openpyxl 3.0.7
I can’t import it in jupyter notebook but in pycharm
import openpyxl
print(openpyxl.__version__)
shows 3.0.7
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
No module named 'openpyxl' - Python 3.4 - Ubuntu
In order to keep track of dependency issues, I like to use the conda installer, which simply boils down to: conda install openpyxl....
Read more >Use pip or conda to install openpyxl - Datalore Forum
ExcelFile('yelp.xlsx')), I got a msg: 'ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
Read more >Fix ModuleNotFoundError (No Module Named openpyxl ...
In this tutorial I'll show you how to install and import openpyxl ... ( No Module Named openpyxl ) Python Import Error (If...
Read more >despite already having openpyxl installed, I'm receiving an ...
ImportError : Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl. However, when I use pip list
Read more >initial prompt for reading .xlsx files misleadingly refers to xlrd ...
This is actually fixed on master where it will only say ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like you are using different environments
Yeah but you haven‘t installed openpyxl in the env, so nothing we can do about from our side