Error printing label cannot import name 'ImageDraw' from 'PIL' (/root/.local/lib/python3.11/site-packages/PIL/__init__.py)
Please verify that this bug has NOT been raised before.
- [x] I checked and didn't find a similar issue
Describe the bug*
Hi,
its not possible to print a label. After clicking on the Print button, the following error code plobs up.
Error printing label
cannot import name 'ImageDraw' from 'PIL' (/root/.local/lib/python3.11/site-packages/PIL/init.py)
it dusent matter, whitch Print method is used.
Steps to Reproduce
1 go to Print Actions 2 Print Label
Expected behaviour
Print a Label or Generate PDF
Deployment Method
- [x] Docker
- [ ] Package
- [ ] Bare metal
- [ ] Other - added info in Steps to Reproduce
Version Information
New Deployed Version, now Update etc.
77ae06b03ba5 inventree/inventree:stable "/bin/ash ./init.sh …" 21 minutes ago Up 21 minutes 8000/tcp inventree-worker 16124c1834c1 caddy:alpine "caddy run --config …" 21 minutes ago Up 21 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 443/udp, 2019/tcp inventree-proxy db55c3ab38f9 inventree/inventree:stable "/bin/ash ./init.sh …" 21 minutes ago Up 21 minutes 8000/tcp inventree-server 6bbe316798dc postgres:13 "docker-entrypoint.s…" 21 minutes ago Up 21 minutes 5432/tcp inventree-db 478056b8e58f redis:7.0 "docker-entrypoint.s…" 21 minutes ago Up 21 minutes 6379/tcp
Please verify if you can reproduce this bug on the demo site.
- [ ] I can reproduce this bug on the demo site.
Relevant log output
@Agilitytime please include the full error log - which should be available via the admin interface
If you are not seeing any error messages there you may need to enable the Log Report Errors setting
Hi, I have the same problem, Did you found a solution ?
@gab696 are you using docker also?
@gab696 are you using docker also?
Yes, a fresh install of the last stable release 0.17.1 / Debian 11
@gab696 I cannot reproduce this on what I think is the same setup. Label printing works just fine!
Can you please share the following:
System Information
Version Info
> docker compose run --rm inventree-server invoke version
InvenTree - inventree.org
The Open-Source Inventory Management System
Python paths:
Executable /usr/local/bin/python
Environment /usr/local
Installation paths:
Base /home/inventree
Config /home/inventree/data/config.yaml
Media /home/inventree/data/media
Static /home/inventree/data/static
Versions:
Python 3.11.9
Django 4.2.17
InvenTree 0.17.1
API 294
Node N/A
Yarn N/A
Commit hash: eed6223
Commit date: 2024-12-26
PIL Library Version
> docker compose run --rm inventree-server pip show pillow
Name: pillow
Version: 11.0.0
Summary: Python Imaging Library (Fork)
Home-page:
Author:
Author-email: "Jeffrey A. Clark" <[email protected]>
License: MIT-CMU
Location: /root/.local/lib/python3.11/site-packages
Requires:
Required-by: django-stdimage, pdf2image, weasyprint
@gab696 / @Agilitytime please provide the above requested information for reproduction - we can not reproduce this without it.
This issue seems stale. Please react to show this is still important.
I am having the same error, please see the full error log below:
Traceback (most recent call last):
File "/home/inventree/src/backend/InvenTree/report/api.py", line 271, in print
plugin.print_labels(
File "/home/inventree/src/backend/InvenTree/plugin/base/label/mixins.py", line 156, in print_labels
pdf_data = pdf_file.get_document().write_pdf()
^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django_weasyprint/views.py", line 81, in get_document
string=super().rendered_content,
^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/response.py", line 92, in rendered_content
return template.render(context, self._request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 175, in render
return self._render(context)
^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 167, in _render
return self.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/loader_tags.py", line 157, in render
return compiled_parent._render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 167, in _render
return self.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/loader_tags.py", line 63, in render
result = block.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/library.py", line 237, in render
output = self.func(*resolved_args, **resolved_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/inventree/src/backend/InvenTree/report/templatetags/barcode.py", line 85, in qrcode
qri = qr.make_image(fill_color=fill_color, back_color=back_color)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/qrcode/main.py", line 363, in make_image
from qrcode.image.pil import Image, PilImage
File "/root/.local/lib/python3.11/site-packages/qrcode/image/pil.py", line 2, in <module>
from PIL import Image, ImageDraw
ImportError: cannot import name 'ImageDraw' from 'PIL' (/root/.local/lib/python3.11/site-packages/PIL/__init__.py)
I am running it in a docker container as well on a debian 11 system. The inventree version is 0.17.10, the python version is 3.11.9 and the Django version is 4.2.17. If there is any other information you need, please let me know, I'd be more than happy to provide it.
I have also tried a different plugin (Niimbot plugin) which gives:
Traceback (most recent call last):
File "/home/inventree/src/backend/InvenTree/report/api.py", line 271, in print
plugin.print_labels(
File "/home/inventree/src/backend/InvenTree/plugin/base/label/mixins.py", line 156, in print_labels
pdf_data = pdf_file.get_document().write_pdf()
^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django_weasyprint/views.py", line 81, in get_document
string=super().rendered_content,
^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/response.py", line 92, in rendered_content
return template.render(context, self._request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 175, in render
return self._render(context)
^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 167, in _render
return self.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/loader_tags.py", line 157, in render
return compiled_parent._render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 167, in _render
return self.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/loader_tags.py", line 63, in render
result = block.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/django/template/library.py", line 237, in render
output = self.func(*resolved_args, **resolved_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/inventree/src/backend/InvenTree/report/templatetags/barcode.py", line 85, in qrcode
qri = qr.make_image(fill_color=fill_color, back_color=back_color)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/qrcode/main.py", line 363, in make_image
from qrcode.image.pil import Image, PilImage
File "/root/.local/lib/python3.11/site-packages/qrcode/image/pil.py", line 2, in <module>
from PIL import Image, ImageDraw
ImportError: cannot import name 'ImageDraw' from 'PIL' (/root/.local/lib/python3.11/site-packages/PIL/__init__.py)
@sufyan-mukadam can you provide the following (from within your docker container):
pip show PIL
pip show Pillow
@sufyan-mukadam can you provide the following (from within your docker container):
pip show PIL pip show Pillow
Sure, am I correct in running the following commands docker compose run inventree-server pip show PIL and docker compose run inventree-server pip show Pillow. If I am, the following outputs are received:
sudo docker compose run inventree-server pip show PIL
[+] Creating 2/2
✔ Container inventree-db Running 0.0s
✔ Container inventree-cache Running 0.0s
Loading config file : /home/inventree/data/config.yaml
WARNING: Package(s) not found: PIL
sudo docker compose run inventree-server pip show Pillow
[+] Creating 2/2
✔ Container inventree-cache Running 0.0s
✔ Container inventree-db Running 0.0s
Loading config file : /home/inventree/data/config.yaml
Name: pillow
Version: 11.0.0
Summary: Python Imaging Library (Fork)
Home-page:
Author:
Author-email: "Jeffrey A. Clark" <[email protected]>
License: MIT-CMU
Location: /root/.local/lib/python3.11/site-packages
Requires:
Required-by: django-stdimage, pdf2image, weasyprint
Hope this helps, if the commands are incorrect please let me know what to run and I shall.
EDIT:
I also realised you had asked for > docker compose run --rm inventree-server invoke version in a previous comment so decided to add that as well:
InvenTree - inventree.org
The Open-Source Inventory Management System
Python paths:
Executable /usr/local/bin/python
Environment /usr/local
Installation paths:
Base /home/inventree
Config /home/inventree/data/config.yaml
Media /home/inventree/data/media
Static /home/inventree/data/static
Versions:
Python 3.11.9
Django 4.2.17
InvenTree 0.17.10
API 294
Node N/A
Yarn N/A
Commit hash: 8d206bd
Commit date: 2025-04-06
Very strange. I have just tested again, on the stable docker setup, and see no such issues. I have been able to print a label with a QR code without issue:
Can you please confirm what you are doing when you encounter this error? With screenshots if possible.
Sure @SchrodingersGat, please see the attached video:
https://github.com/user-attachments/assets/04506339-1bec-4634-9807-015170ddbd83
I may have stumbled upon the reason for these errors. I decided to set up a new instance of inventree and added a test part and everything worked as expected. I followed by migrating my part and media data to the new install and this worked as well, the labels were correctly generated.
I had also previously installed a plugin https://github.com/piramja/inventree-niimbot-plugin.git and as soon as I installed this the errors reappeared. The plugin in its setup file requires pillow==10.3.0 while inventree is on 11.0.0. I am unsure if this is the cause (I checked the release notes for Pillow 11.0.0 but couldn't see anything obvious) but I would be willing to test it with some guidance.
@sufyan-mukadam an interesting discovery - and probably worth raising an issue with the plugin author, pinning versions of packages like that will override the InvenTree libraries when the plugin is installed.
However, I do not think this is the core issue here, even with that particular version of pillow installed, I do not get the same error message.
@SchrodingersGat I will raise an issue with the developer and in the meantime will also keep looking to see if I can figure out the root cause. If you need me to test anything, please let me know, I am open to contributing however I can.