Pillow and textsize/textwidth

937 views
Skip to first unread message

Greg Troxel

unread,
Oct 24, 2023, 9:06:27 AM10/24/23
to weewx...@googlegroups.com
Sorry if this has been discussed before, but tldr: the tip of master
seems incompatible with Pillow 10 while declaring that it is compatible.

I'm doing the usual quarterly updating of packages. I now have
py311-Pillow-10.0.1
which is consistent with requirements.txt.

My weewx sources are at

commit 26bbcc56b5939d3e7e102ba21e9e656074714f67 (origin/master, origin/HEAD)
Merge: 548bf5ec 8b3e628c
Author: Tom Keffer <tke...@gmail.com>
Date: Sun Jul 16 16:08:00 2023 -0700

Running wee_reports:

Generating as of last timestamp in the database.
Using configuration file /usr/weewx/weewx.conf
Traceback (most recent call last):
File "/usr/weewx/bin/weewx/reportengine.py", line 197, in run
obj.start()
File "/usr/weewx/bin/weewx/reportengine.py", line 385, in start
self.run()
File "/usr/weewx/bin/weewx/imagegenerator.py", line 42, in run
self.gen_images(self.gen_ts)
File "/usr/weewx/bin/weewx/imagegenerator.py", line 114, in gen_images
image = plot.render()
^^^^^^^^^^^^^
File "/usr/weewx/bin/weeplot/genplot.py", line 212, in render
self._renderBottom(draw)
File "/usr/weewx/bin/weeplot/genplot.py", line 404, in _renderBottom
bottom_label_size = draw.textsize(self.bottom_label, font=bottom_label_font)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/weewx/bin/weeplot/genplot.py", line 646, in textsize
return ImageDraw.ImageDraw.textsize(self, string, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'ImageDraw' has no attribute 'textsize'

and the Internet more or less says that Pillow has changed this to
textlength.

Pillow says this removal is a feature rather than a bug:

https://github.com/python-pillow/Pillow/issues/7277

https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods



Replaying textsize with textlength in bin/weeplot/genplot.py results in
further errors, because apparently textsize returns a tuple but
textlength is only length and you need rows * height, but now I'm really
fuzzy.



So other than "it would be better not to depend on upstreams that
withdraw things people use", I wonder what the status is.

Greg Troxel

unread,
Oct 24, 2023, 9:22:14 AM10/24/23
to weewx...@googlegroups.com
Rolling back to py-Pillow 9.5.0, plots generate. That's ok for me today
because the box that runs weewx runs only weewx, but it's obviously not
long-term viable.

(I'm not trying to run v5, because it's structurally different (no
setup.py) and thus a fair bit of work, and because it's not released.)

I have the impression that the replacment functions for textsize are
present in older Pillow, so perhaps changing to those is reasonable. I
didn't try that because a source fix was seeming no longer a 15 minute
thing, and my priority was to get my system working.

Tom Keffer

unread,
Oct 24, 2023, 9:50:31 AM10/24/23
to weewx...@googlegroups.com
This was fixed in commit dc4ab54, to appear in V5.


--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/rmih6mg6tq9.fsf%40s1.lexort.com.

Greg Troxel

unread,
Oct 24, 2023, 11:53:57 AM10/24/23
to Tom Keffer, weewx...@googlegroups.com
Tom Keffer <tke...@gmail.com> writes:

> This was fixed in commit dc4ab54
> <https://github.com/weewx/weewx/commit/dc4ab54b9a5935e7334dc0e9de97e5854204d6e7>,
> to appear in V5.

Thanks for pointing thta tout. Can that be cherrypicked to the v4
(current stabl AIUI) branch? I can certainly try it. (My impression is
that currently, the recommendation is for random users to run v4.)

Greg Troxel

unread,
Oct 24, 2023, 12:43:55 PM10/24/23
to Tom Keffer, weewx...@googlegroups.com
Tom Keffer <tke...@gmail.com> writes:

> This was fixed in commit dc4ab54
> <https://github.com/weewx/weewx/commit/dc4ab54b9a5935e7334dc0e9de97e5854204d6e7>,
> to appear in V5.

I did a cherry-pick of this onto master, which succeeded with no
conflicts. Rerunning setup.py build/install, and then reinstalling
Pillow 10.0.1 (updating it from 9.x), I am able to run wee_reports with
no issues.

I rebooted and waited for a new archive interval, and I am getting new
graphs reliably, as far as I can tell.

So cherry-pick/push on master should be safe.

Thanks,
Greg

Cat22

unread,
Oct 30, 2023, 7:21:43 AM10/30/23
to weewx-user
How do i get this fix? and how do i install it so it only upgrades my weewx without loss of configuration data?
I don't have the option to roll back pillow and I am currently on pillow 10.0.1-1

Greg Troxel

unread,
Oct 30, 2023, 8:28:35 AM10/30/23
to weewx-user
[top posting repaired]

Cat22 <erben...@gmail.com> writes:

> On Tuesday, October 24, 2023 at 9:43:55 AM UTC-7 Greg Troxel wrote:
>
>> Tom Keffer <tke...@gmail.com> writes:
>>
>> > This was fixed in commit dc4ab54
>> > <
>> https://github.com/weewx/weewx/commit/dc4ab54b9a5935e7334dc0e9de97e5854204d6e7
>> >,
>> > to appear in V5.
>>
>> I did a cherry-pick of this onto master, which succeeded with no
>> conflicts. Rerunning setup.py build/install, and then reinstalling
>> Pillow 10.0.1 (updating it from 9.x), I am able to run wee_reports with
>> no issues.
>>
>> I rebooted and waited for a new archive interval, and I am getting new
>> graphs reliably, as far as I can tell.
>>
>> So cherry-pick/push on master should be safe.

> How do i get this fix? and how do i install it so it only upgrades my weewx
> without loss of configuration data?
> I don't have the option to roll back pillow and I am currently on pillow
> 10.0.1-1
>

Ideally, someone who can write the repo would cherry-pick and push to
the stable branch, and then you'd just check that out and build.
Until then, you'll need to clone the repo, and
```
git cherry-pick dc4ab54b9a5935e7334dc0e9de97e5854204d6e7
```
and then build.

If this sounds mysterious, read this book carefully, and then it will
make sense:

https://git-scm.com/book/en/v2




Tom Keffer

unread,
Oct 30, 2023, 9:23:27 AM10/30/23
to weewx...@googlegroups.com
I've done exactly this. The fix is in the master branch.

Cat22: replace your version of genplot.py with this one.

I'm curious why you can't rollback your version of Pillow. 

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.

Greg Troxel

unread,
Oct 30, 2023, 10:21:25 AM10/30/23
to Tom Keffer, weewx...@googlegroups.com
Tom Keffer <tke...@gmail.com> writes:

> I've done exactly this. The fix is in the master branch.

Great, thanks. I've rebased and git has nicely decided that my
cherry-pick and yours don't actually conflict and just taken yours.

> I'm curious why you can't rollback your version of Pillow.

I'm not the one asking, but generally it makes sense to follow along
with one's packaging system, and for every program that thinks that
version is too new, there is another that thinks the previous is too
old. And while I'm not explicitly aware of CVEs for Pillow, in general
the only reasonable approach is to run maintained versions of
everything, and most upstreams do not maintain anything except the most
recent release. So while somebody could go back to old Pillow, I feel
that this isn't a good strategy, and intentionally being on an old
version is a situation that needs a get-well plan.


Tom Keffer

unread,
Oct 30, 2023, 10:31:02 AM10/30/23
to Greg Troxel, weewx...@googlegroups.com
One of the reasons why I have come to prefer using pip and virtual environments over the package installers. It's super easy to maintain "known-good" versions of the Python run environment.

Greg Troxel

unread,
Oct 30, 2023, 10:41:30 AM10/30/23
to Tom Keffer, weewx...@googlegroups.com
Tom Keffer <tke...@gmail.com> writes:

> One of the reasons why I have come to prefer using pip and virtual
> environments over the package installers. It's super easy to maintain
> "known-good" versions of the Python run environment.

Yes, but this leads to having multiple copies of everything and no way
to audit that any of them are out of date. And when they are, you can't
update them without breaking the property you want, that they are the
known-working ones. Once a library is no longer maintained, there's no
reason to expect any vulnerabilities to be noticed or reported, so I
consider no-longer-maintained versions as basically unsafe (in a mild
perhaps kind of way, but still).

The real issue is that projects maintaining libraries break backwards
compatibility, and on the other hand LTS distributions have egregiously
old code. Thus projects like weewx have to support the current as well
as very old releases, or users have trouble. If that ends up being too
hard, I lean to supporting the current release and as far back as isn't
painful, not worrying too much about LTS. That's what I've done
maintaining unison, where we've desupported quite old ocaml versions
still in LTS distributions.

In this case, it seems the source adaptation wasn't that hard, which was
fortunate. If this is hard for some library, that's a clue that the
library is too unstable to use, which I realize is easier said than
actually switching away from.

Denny Page

unread,
Oct 31, 2023, 11:55:03 AM10/31/23
to weewx-user
With this version against pillow 10.0.1, I am receiving an error for the antialias use:

 Caught unrecoverable exception in generator 'weewx.imagegenerator.ImageGenerator'

         ****  module 'PIL.Image' has no attribute 'ANTIALIAS'

         ****  Traceback (most recent call last):

         ****    File "/home/weewx/bin/weewx/reportengine.py", line 197, in run

         ****      obj.start()

         ****    File "/home/weewx/bin/weewx/reportengine.py", line 385, in start

         ****      self.run()

         ****    File "/home/weewx/bin/weewx/imagegenerator.py", line 42, in run

         ****      self.gen_images(self.gen_ts)

         ****    File "/home/weewx/bin/weewx/imagegenerator.py", line 114, in gen_images

         ****      image = plot.render()

         ****              ^^^^^^^^^^^^^

         ****    File "/home/weewx/bin/weeplot/genplot.py", line 230, in render

         ****      image.thumbnail((self.image_width / self.anti_alias, self.image_height / self.anti_alias), Image.ANTIALIAS)

         ****                                                                                                 ^^^^^^^^^^^^^^^

         ****  AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

         ****  Generator terminated



Greg Troxel

unread,
Oct 31, 2023, 12:25:10 PM10/31/23
to Denny Page, weewx-user
ANTIALIAS was also removed in 10:

https://pillow.readthedocs.io/en/stable/deprecations.html

I suggest:

don't set anti_alias

change the code per the above page

Tom Keffer

unread,
Oct 31, 2023, 12:50:36 PM10/31/23
to weewx...@googlegroups.com, Denny Page
Sorry about that. Commit 2482eebf also needed to be cherry-picked. Try HEAD now.

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.

Denny Page

unread,
Oct 31, 2023, 1:00:04 PM10/31/23
to Tom Keffer, weewx...@googlegroups.com
That’s got it, thanks.

Cat22

unread,
Nov 1, 2023, 11:46:06 AM11/1/23
to weewx-user
Tom Keffer: 
Thanks for the updated genplot.py, i just now copied it over,
I watched it through a cycle and the problem has resolved itself. I'll
double check after a few hours just to be sure.
As to your question:
I cant roil back because Ysat shows no previous version of pillow and when i try to use
python3 -m pip install Pillow==9.5.0
 to roll back it wont let me because it says:
"error: externally-managed-environment"
i tried uninstalling pillow with Yast but it still got that same error.
Thanks Again!
Cat22

Tom Keffer

unread,
Nov 1, 2023, 8:35:16 PM11/1/23
to weewx...@googlegroups.com
This problem is caused by the enforcement of PEP 668. It will become more and more common in the future.

The solution is to use a virtual environment. Alternatively you can tell pip, "I don't care! Install anyway!" by using the option "--break-system-packages".

Cat22

unread,
Nov 1, 2023, 9:30:55 PM11/1/23
to weewx-user
I tried that --break-system-packages but no matter where i inserted it it didn't like it and I couldn't find an example of its proper use.
also, pip --help   doesn't list that option

Tom Keffer

unread,
Nov 1, 2023, 9:47:37 PM11/1/23
to weewx...@googlegroups.com
I must admit, I've never tried it!

But, virtual environments definitely work. Indeed, if you're using pip, they are the preferred installation method for V5. 

vince

unread,
Nov 1, 2023, 11:12:22 PM11/1/23
to weewx-user
Which precise os version are you running ?
I can try to recreate your issue but I don't understand which version is which for anything SUSE.

Cat22

unread,
Nov 2, 2023, 1:57:58 AM11/2/23
to weewx-user
opesSuse Tumbleweed 10-16-2023

vince

unread,
Nov 2, 2023, 2:13:21 AM11/2/23
to weewx-user

And your python and versions ?

vince

unread,
Nov 2, 2023, 3:03:58 AM11/2/23
to weewx-user
In a docker container using the most recent tumbleweed image "pip3 install --break-system-packages --user paho-mqtt" worked for me, as one example.  I installed python311 and python311-pip if that matters.

Cat22

unread,
Nov 3, 2023, 6:19:29 AM11/3/23
to weewx-user

python 3.11.5
I see the issue tho (I think), I was using pip instead of pip3
Reply all
Reply to author
Forward
0 new messages