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

changes done in 4th april introduced a regression #398

Closed
categulario opened this issue Apr 21, 2022 · 5 comments
Closed

changes done in 4th april introduced a regression #398

categulario opened this issue Apr 21, 2022 · 5 comments

Comments

@categulario
Copy link

categulario commented Apr 21, 2022

Describe the bug

Error details
I updated fpdf to 2.5.2 (latest at the moment of writing) while keeping pillow in 7.0.0. Code that was working no longer is because commit 4acaaec introduced a dependency on enums added in pillow==9.1.0 (python-pillow/Pillow#5954).

here is the traceback

  File "project/.venv/lib/python3.8/site-packages/fpdf/fpdf.py", line 265, in wrapper
    return fn(self, *args, **kwargs)
  File "project/.venv/lib/python3.8/site-packages/fpdf/fpdf.py", line 3131, in image
    info = self._downscale_image(name, img, info, w, h)
  File "project/.venv/lib/python3.8/site-packages/fpdf/fpdf.py", line 3261, in _downscale_image
    info = get_img_info(
  File "project/.venv/lib/python3.8/site-packages/fpdf/image_parsing.py", line 50, in get_img_info
    img = img.resize(dims, resample=Image.Resampling.LANCZOS)
  File "project/.venv/lib/python3.8/site-packages/PIL/Image.py", line 62, in __getattr__
    raise AttributeError("module '{}' has no attribute '{}'".format(__name__, name))
AttributeError: module 'PIL.Image' has no attribute 'Resampling'

Minimal code

I just called pdf.image() really. As mentioned earlier, the code was working, now it is not.

Environment

  • Linux
  • pytthon 3.8
  • fpdf2 2.5.2

Problem is introduced in:

https://github.com/PyFPDF/fpdf2/blob/master/fpdf/image_parsing.py#L50

@Lucas-C
Copy link
Member

Lucas-C commented Apr 21, 2022

Hi @categulario and thanks for reporting this.

I don't think we have really discussed this before,
but fpdf2 is expected to work with the latest version of Pillow, not necesseraliy all versions of Pillow.

Can't you simply upgrade your version of Pillow?

If you really have a need to use pillow==7.0.0, I think we can make fpdf2 compatible.
Feel free to submit a PR if you wish

@categulario
Copy link
Author

Ok, I updated pillow to 9.1.0 and now the code works.

What can be done in this kind of situation? update setup.py to reflect compatible version of pillow? add testing with a matrix of versions of pillow?

will close for now, but I suspect I'm not the only one, I'm just the one reported it first...

@Lucas-C
Copy link
Member

Lucas-C commented Apr 21, 2022

What can be done in this kind of situation?

It depends a lot on your usage...
Usually I would recommend dependency locking, for example using poetry.
This kind of tool provides commands for upgrading your dependencies "intelligently".

But for basic usage, pip install --upgrade should be enough:

pip install --upgrade $path/to/python/project/dir   # containing a setup.py or setup.cfg
# or
pip install --upgrade -r requirements.txt

Those commands will upgrade all yours dependencies at once,
and hence you would not have face the error you got by only upgrading fpdf2

@Lucas-C
Copy link
Member

Lucas-C commented Apr 22, 2022

On second thought, you were right, I was missing something:
I added a minimum Pillow version in setup.py: https://github.com/PyFPDF/fpdf2/blob/master/setup.py#L36

@categulario
Copy link
Author

;) 🙏🏽

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

2 participants