0 x01: overture

 

Error: Python is used to read the XLSX file in pandas.

ImportError: Missing optional dependency ‘XLRD ‘. Install XLRD >= 1.0.0 for Excel support Use PIP or conda to Install XLRD.

It seems to be simple to install XLRD directly, but in fact the operation is not smooth, and other errors are reported. Here I share my problems and solutions.

 

0 x02: history

Use PIP or conda to install XLRD.

pip install xlrd
Copy the code

The output is as follows: XLRD 2.0.1 has been installed. XLRD >= 1.0.0 is sufficient.

(ml) bash-3.2$PIP install XLRD Lookinginindexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting xlrd Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a6/0c/c2a72d51fe56e08a08acc85d13013558a2d793028ae7385448a6ccdfae64/xlrd-2.0.1 - py2. Py3 - none - any. WHL (96 kB) | █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ | 96 kB 1.1 MB/s Installing collected packages: XLRD Successfully installed XLRD - 2.0.1Copy the code

However, the following error is reported when executing the code:

(ml) bash-3.2$python demo.py Traceback (most recent Call last): File"demo.py", line 6, in <module>
    datas = pd.read_excel("data.xlsx")
  File "/ Users/song/miniforge3 / envs/ml/lib/python3.8 / site - packages/pandas/util / _decorators py." ", line 299, in wrapper
    return func(*args, **kwargs)
  File "/ Users/song/miniforge3 / envs/ml/lib/python3.8 / site - packages/pandas/IO/excel / _base py." ", line 336, in read_excel
    io = ExcelFile(io, storage_options=storage_options, engine=engine)
  File "/ Users/song/miniforge3 / envs/ml/lib/python3.8 / site - packages/pandas/IO/excel / _base py." ", line 1080, in__init__ raise ValueError( ValueError: Your version of XLRD is 2.0.1. In XLRD >= 2.0, only the XLS format is supported.Copy the code

Your version of XLRD is 2.0.1. In XLRD >= 2.0, only the XLS format is supported.

If the XLRD version is greater than or equal to 2.0, only the XLS format is supported. You are advised to install OpenPyXL.

There are actually two solutions:

  • XLRD is degraded to support XLSX
  • Install OpenPyXL instead of relying on XLRD

PIP install XLRD ==1.0

1. “==” the symbol is used to specify the version. Note that the double equals sign is different from the single equals sign of conda. 2. When using PIP to downgrade the installation, it is not necessary to manually uninstall the older version, the system will replace it directly.

(ml) bash-3.2$ pip install xlrd==1
Looking inindexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting xlrd==1 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0c/b0/8946fe3f9c2690c164aaa88dfd43b56347d3cdeac34124b988acd1aaa151/xlrd-1.0.0 - py3 - none - any WHL (143 kB) | █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ | 143 kB, 150 kB/s Installing collected packages: XLRD Attempting uninstall: XLRD Found Existing installation: XLRD 2.0.0 Uninstalling xlrd-2.0.0: Successfully uninstalled xlrd-2.0.0 Successfully installed xlrd-1.0.0Copy the code

I have installed version 1.0 here, but unfortunately it is running in error ~~, as follows:

(ml) bash-3.2$python demo.py Traceback (most recent Call last): File"demo.py", line 6, in <module>
    datas = pd.read_excel("data.xlsx")
  File "/ Users/song/miniforge3 / envs/ml/lib/python3.8 / site - packages/pandas/util / _decorators py." ", line 299, in wrapper
    return func(*args, **kwargs)
  File "/ Users/song/miniforge3 / envs/ml/lib/python3.8 / site - packages/pandas/IO/excel / _base py." ", line 336, in read_excel
    io = ExcelFile(io, storage_options=storage_options, engine=engine)
  File "/ Users/song/miniforge3 / envs/ml/lib/python3.8 / site - packages/pandas/IO/excel / _base py." ", line 1052, in __init__
    xlrd_version = LooseVersion(xlrd.__version__)
AttributeError: module 'xlrd' has no attribute '__version__'
Copy the code

Continue to try to solve, I consider, may be 1.0 version too old cause. I tried to install version 1.x. After a few tries, install 1.2:

(ml) bash-3.2$ pip install xlrd==1.8
Looking inindexes: https://pypi.tuna.tsinghua.edu.cn/simple ERROR: Could not find a version that distribution the requirement XLRD ==1.8 ERROR: No matching distribution foundforXLRD ==1.8 (ml) bash-3.2$PIP install XLRD ==1.6 Lookinginindexes: https://pypi.tuna.tsinghua.edu.cn/simple ERROR: Could not find a version that distribution the requirement XLRD ==1.6 ERROR: No matching distribution foundforXLRD ==1.6 (ml) bash-3.2$PIP install XLRD ==1.2 Lookinginindexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting XLRD = = 1.2 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b0/16/63576a1a001752e34bf8ea62e367997530dc553b689356b9879339cf45a4/xlrd-1.2.0 - py2. Py3 - none - any. WHL (103 kB) | █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ | 103 kB, 61 kB/s Installing collected packages: XLRD Attempting Uninstall: XLRD Found Existing installation: XLRD 1.0.0 Uninstalling XLrD-1.0.0: Successfully uninstalled xlrd-1.0.0 Successfully installed xlrd-1.2.0Copy the code

The reading is now normal.

 

0 x03: postscript

 

This blog for your useful words welcome to collect and forward, but also trouble lovely and love to learn you can appreciate a praise, food song more bo is not easy, thank you here.

If you want to learn more development skills and AI algorithms, please search our official account “Concise AI”, and learn with your friends who love learning and discussing.