-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Python3: No module named 'openpyxl.style' #9060
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
Comments
@upthewazoo you have a fairly old version of pandas w.r.t. these types of features. They have been updated in 0.14.* and 0.15.* cc @neirbowj This looks like a newwer version of |
openpyxl 2.1.1 through 2.1.4 have all been released since I last checked for breakage. I'll take a look but the first step to resolve this issue is either to use an expected-compatible pair of versions; upgrade pandas or downgrade openpyxl. |
There are a few changes to the |
Thank you for doing some digging and getting back to me. The instructions on the pandas website for installation (Linux: Debian/Ubuntu) was used Note that the pandas documentation still mentions "openpyxl version 1.6.1 or higher" for the 13.1 branch installation requirements for openpyxl (the page named install.html). But the 14.1 version of the install.html page puts an upper bounds cap on the requirement "openpyxl version 1.6.1 or higher, but lower than 2.0.0". It would help us repository installers who have to install openpyxl by hand with pip to have an upper version cap added to the pandas website 13.1 documentation (install.html) so we can feed pip the parameter to install a version of openpyxl less than or equal to the upper bound for 13.1 branch's ability to support the API of openpyxl. I can manually do this right now for my situation, I may play with the 14.1 upper bounds limit to see if it still works in 13.1 branch of pandas.
IPython 1.2.1 -- An enhanced Interactive Python.
Rerun my ipython3 notebook ---> Executes without returning an error inside the ipython3 notebook! Cheers! |
Good to know, thanks! |
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.
The text was updated successfully, but these errors were encountered: