openfoodfacts / openfoodfacts-python

🐍 Python package for Open Food Facts
https://openfoodfacts.github.io/openfoodfacts-python/
Other
331 stars 69 forks source link

pillow is not installed with the package #257

Closed gitting closed 1 month ago

gitting commented 3 months ago

What

Runningpip install openfoodfacts results with the following in a fresh venv:

annotated-types==0.7.0
certifi==2024.7.4
charset-normalizer==3.3.2
idna==3.7
openfoodfacts==1.1.1
pydantic==2.8.2
pydantic_core==2.20.1
requests==2.32.3
tqdm==4.66.4
typing_extensions==4.12.2
urllib3==2.2.2

pillow is not in the list, hence attempts to use the API result in the following:

Traceback (most recent call last):
  File "/private/tmp/food/test.py", line 1, in <module>
    import openfoodfacts
  File "/private/tmp/food/.venv/lib/python3.12/site-packages/openfoodfacts/__init__.py", line 1, in <module>
    from .api import API
  File "/private/tmp/food/.venv/lib/python3.12/site-packages/openfoodfacts/api.py", line 6, in <module>
    from .utils import URLBuilder, http_session
  File "/private/tmp/food/.venv/lib/python3.12/site-packages/openfoodfacts/utils.py", line 354, in <module>
    ) -> Union[ImageDownloadItem, Image.Image, None]:

After pip install pillow the list looks as follows:

annotated-types==0.7.0
certifi==2024.7.4
charset-normalizer==3.3.2
idna==3.7
openfoodfacts==1.1.1
pillow==10.4.0
pydantic==2.8.2
pydantic_core==2.20.1
requests==2.32.3
tqdm==4.66.4
typing_extensions==4.12.2
urllib3==2.2.2

and the API works.

Steps to reproduce the behavior:

  1. python3 -m venv .venv
  2. source .venv/bin/activate
  3. pip install openfoodfacts
  4. Observe pillow is missing

Expected behavior

pillow should be installed as a required dependency.

Could it be because of the optional = True key set in this line? https://github.com/openfoodfacts/openfoodfacts-python/blob/8d1013a01c8fa674c1c84fd1729b73c621b5edd3/pyproject.toml#L26

Platform (Desktop, Mobile, Hunger Games)

benbenben2 commented 1 month ago

Same issue

And many thanks @gitting for the workaround :+1:

teolemon commented 1 month ago

there might be a good reason (pillow is using native code afaik, which might fail sometimes, so that might be the reason for making it optional). @raphael0202 any opinions

raphael0202 commented 1 month ago

I missed this issue, sorry for that! We support a degraded version of openfoodfacts-python without Pillow (if you don't need image processing, no need to have Pillow installed). I've just released a new version of openfoodfacts-python (1.1.3) that fixes this issue.

I'm closing this issue as it works locally without Pillow, but feel free to reopen if the issue persists.