python-barcode icon indicating copy to clipboard operation
python-barcode copied to clipboard

ImageWriter can't be instanciated

Open arthuRHD opened this issue 3 years ago • 2 comments

Env:

  • python-barcode v0.13.1
  • python 3.8.10

Whenever I try to store a picture without the default SVG writer, tjis error shows up

>>> iw = ImageWriter(format="PNG")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable

After looking at the code, there is an IF statement that prevent the class declaration in barcode/writer.py at line 330.

if Image is None:
    ImageWriter = None
else:

    class ImageWriter(BaseWriter):  # type: ignore
        format: str
        mode: str
        dpi: int
        ...

arthuRHD avatar Dec 24 '21 11:12 arthuRHD

nvm, should had checked the head of the file. Everything is fixed when I installed PIL.

It would be nice to include PIL as a package requirement.

arthuRHD avatar Dec 24 '21 12:12 arthuRHD

It would be nice to include PIL as a package requirement.

See https://python-barcode.readthedocs.io/en/stable/getting-started.html#installation

PIL is not required if you're only generating SVG barcodes. I guess the error could be improved and point to the docs, so I'll keep this open as a reminder to improve the docs.

WhyNotHugo avatar May 17 '22 16:05 WhyNotHugo