Skip to content

Python3: No module named 'openpyxl.style' #9060

Closed
@upthewazoo

Description

@upthewazoo

There is no module named openpyxl.style on the Python3 version of openpyxl. There is, however a openpyxl.styles module in the namespace of openpyxl. But a simply name change update on line 577 of pandas/io/excel.py isn't the quick fix as there are other differences causing errors.

My offending code:
diff_output = diff_panel.apply(report_diff, axis=0)

def has_change(row):
if "--->" in row.to_string():
return "Y"
else:
return "N"

diff_output['has_change'] = diff_output.apply(has_change, axis=1)

-->diff_output[(diff_output.has_change == 'Y')].to_excel('my-diff.xlsx')

Stacktrace tail

.
.
.
/usr/lib/python3/dist-packages/pandas/io/excel.py in _convert_to_style(cls, style_dict)
575 """
576
--> 577 from openpyxl.style import Style
578 xls_style = Style()
579 for key, value in style_dict.items():

ImportError: No module named 'openpyxl.style'

Name: openpyxl
Version: 2.1.3
Location: /usr/local/lib/python3.4/dist-packages
Requires: jdcal

Name: jdcal
Version: 1.0
Location: /usr/local/lib/python3.4/dist-packages
Requires:

Python 3.4.0 (default, Apr 11 2014, 13:05:11)
Type "copyright", "credits" or "license" for more information.

IPython 1.2.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]: import pandas

In [2]: pandas.__version__
Out[2]: '0.13.1'

Modified 577

(-)from openpyxl.style import Style
(+)from openpyxl.styles import Styles

New Stacktrace


TypeError Traceback (most recent call last)
in ()
----> 1 diff_output[(diff_output.has_change == 'Y')].to_excel('my-diff.xlsx')

/usr/lib/python3/dist-packages/pandas/core/frame.py in to_excel(self, excel_writer, sheet_name, na_rep, float_format, cols, header, index, index_label, startrow, startcol, engine, merge_cells)
1202 formatted_cells = formatter.get_formatted_cells()
1203 excel_writer.write_cells(formatted_cells, sheet_name,
-> 1204 startrow=startrow, startcol=startcol)
1205 if need_save:
1206 excel_writer.save()

/usr/lib/python3/dist-packages/pandas/io/excel.py in write_cells(self, cells, sheet_name, startrow, startcol)
528 style = None
529 if cell.style:
--> 530 style = self._convert_to_style(cell.style)
531 for field in style.fields:
532 xcell.style.setattr(field,

/usr/lib/python3/dist-packages/pandas/io/excel.py in _convert_to_style(cls, style_dict)
583 .setattr('border_style', nv))
584 else:
--> 585 xls_style.getattribute(key).setattr(nk, nv)
586
587 return xls_style

/usr/local/lib/python3.4/dist-packages/openpyxl/styles/hashable.py in setattr(self, _args, *_kwargs)
51 getattr(self, name) is not None
52 and not isinstance(getattr(self, name), Descriptor)):
---> 53 raise TypeError('cannot set %s attribute' % name)
54 return object.setattr(self, _args, *_kwargs)
55

TypeError: cannot set bold attribute

It appears to me that there seems to be sufficient differences in openpyxl between Python2 and Python3. Something the pandas devs might want to be aware of.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsIO Excelread_excel, to_excel

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions