1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.となったときの対応方法

Posted at
  • 環境
    • macOS Catalina バージョン10.15.7
    • Python 3.8.5
    • pandas 1.1.3

事象 : Pandasをつおうとしたら怒られた

Traceback (most recent call last):
  File "/Users/ponsuke/tryPython/main.py", line 7, in <module>
    book = pd.read_excel(excel_file, sheet_name=None, header=None)
  File "/Users/ponsuke/tryPython/venv/lib/python3.8/site-packages/pandas/util/_decorators.py", line 296, in wrapper
    return func(*args, **kwargs)
  File "/Users/ponsuke/tryPython/venv/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 304, in read_excel
    io = ExcelFile(io, engine=engine)
  File "/Users/ponsuke/tryPython/venv/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 867, in __init__
    self._reader = self._engines[engine](self._io)
  File "/Users/ponsuke/tryPython/venv/lib/python3.8/site-packages/pandas/io/excel/_xlrd.py", line 21, in __init__
    import_optional_dependency("xlrd", extra=err_msg)
  File "/Users/ponsuke/tryPython/venv/lib/python3.8/site-packages/pandas/compat/_optional.py", line 110, in import_optional_dependency
    raise ImportError(msg) from None
ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

Process finished with exit code 1
main.py
import pandas as pd

# ...省略...
if __name__ == '__main__':
    excel_file = 'Book.xlsx'
    book = pd.read_excel(excel_file, sheet_name=None, header=None)

原因 : Pandasにはxlrdが必要なのにインストールしていないから

Excelファイルを読み込むためには、xlrdパッケージもインストールする必要があります。
Python Pandasを使ってExcel読み込みと書き込み | アールエフェクト

対応 : xlrdをインストールする

% pip install xlrd
Collecting xlrd
  Downloading xlrd-1.2.0-py2.py3-none-any.whl (103 kB)
     |████████████████████████████████| 103 kB 3.0 MB/s 
Installing collected packages: xlrd
Successfully installed xlrd-1.2.0
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?