[Solved]-Xhtml2pdf ImportError – Django

18πŸ‘

βœ…

In util.py edit the following lines:

if not (reportlab.Version[0] == "2" and reportlab.Version[2] >= "1"):
    raise ImportError("Reportlab Version 2.1+ is needed!")

REPORTLAB22 = (reportlab.Version[0] == "2" and reportlab.Version[2] >= "2")

And set to:

if not (reportlab.Version[:3] >="2.1"):
    raise ImportError("Reportlab Version 2.1+ is needed!")

REPORTLAB22 = (reportlab.Version[:3] >="2.1")

EDIT

While the above works it still uses string literals for version checking. There’s a pull request in the xhtml2pdf project with a more elegant solution that compares versions using tuples of integers. This is the proposed solution:

_reportlab_version = tuple(map(int, reportlab.Version.split('.')))
if _reportlab_version < (2,1):
    raise ImportError("Reportlab Version 2.1+ is needed!")

REPORTLAB22 = _reportlab_version >= (2, 2)
πŸ‘€hanleyhansen

Leave a comment