Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace use of xlrd with openpyxl #86

Closed
dgdekoning opened this issue Jan 7, 2021 · 4 comments
Closed

Replace use of xlrd with openpyxl #86

dgdekoning opened this issue Jan 7, 2021 · 4 comments

Comments

@dgdekoning
Copy link
Member

As noted on the ReadTheDocs page, xlrd will no longer support the reading of .xlsx files as of version 2.0 (shipped the 11th of december).

In response, the newer version of pandas have switched from using xlrd to openpyxl.

I would suggest going with the flow and swapping out excel-reading packages. As the current implementation causes create_default_lcia_methods() to fail when the newest version of xlrd is installed.

 File "C:\Users\me\workspace\activity-browser\activity_browser\app\ui\wizards\db_import_wizard.py", line 1215, in run
    bw.create_default_lcia_methods()
  File "C:\Users\me\AppData\Local\Continuum\miniconda3\envs\ab_test\lib\site-packages\bw2io\__init__.py", line 91, in create_default_lcia_methods
    ei = EcoinventLCIAImporter()
  File "C:\Users\me\AppData\Local\Continuum\miniconda3\envs\ab_test\lib\site-packages\bw2io\importers\ecoinvent_lcia.py", line 30, in __init__
    self.csv_data, self.cf_data, self.units, self.file = convert_lcia_methods_data()
  File "C:\Users\me\AppData\Local\Continuum\miniconda3\envs\ab_test\lib\site-packages\bw2io\data\__init__.py", line 338, in convert_lcia_methods_data
    "CFs"
  File "C:\Users\me\AppData\Local\Continuum\miniconda3\envs\ab_test\lib\site-packages\bw2io\data\__init__.py", line 40, in get_sheet
    wb = xlrd.open_workbook(path)
  File "C:\Users\me\AppData\Local\Continuum\miniconda3\envs\ab_test\lib\site-packages\xlrd\__init__.py", line 170, in open_workbook
    raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
xlrd.biffh.XLRDError: Excel xlsx file; not supported

Relevant code:

def get_sheet(path, name):
wb = xlrd.open_workbook(path)
return wb.sheet_by_name(name)

@tngTUDOR
Copy link
Contributor

tngTUDOR commented Feb 16, 2021

A quick ugly fix would be to pin the version of xlrd to <= 2.0.0
https://xlrd.readthedocs.io/en/latest/changes.html#id1

@tngTUDOR
Copy link
Contributor

For those waiting for a new version of the package that fixes this, you can use conda or pip to downgrade the xlrd package with:

conda install xlrd<2.0.0

or

pip install xrd<2.0.0

@tngTUDOR
Copy link
Contributor

xlrd is used in the following places:

extractors/excel.py
3:import xlrd
18:        wb = xlrd.open_workbook(filepath)
extractors/exiobase.py
5:import xlrd
24:        wb = xlrd.open_workbook(os.path.join(path, "types_version2.2.2.xls"))
data/__init__.py
17:import xlrd
36:    wb = xlrd.open_workbook(path)

@cmutel
Copy link
Member

cmutel commented Feb 24, 2021

Fixed in 0.8 release.

@cmutel cmutel closed this as completed Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants