asweigart / pyscreeze

PyScreeze is a simple, cross-platform screenshot module for Python 2 and 3.
BSD 3-Clause "New" or "Revised" License
191 stars 96 forks source link

Fix pillow version check on macOS #96

Closed bwoodsend closed 1 year ago

bwoodsend commented 1 year ago

dbe9cb89 introduced a version check using PIL.__version__ assuming that that attribute is a int-tuple whereas it's really just a string, leading to a type error on even the most basic usage on macOS:

>>> pyscreeze.screenshot()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/home/notebooks/pyscreeze/pyscreeze/__init__.py", line 527, in _screenshot_osx
    if tuple(PIL__version__) < (6, 2, 1):
TypeError: '<' not supported between instances of 'str' and 'int'

Convert the offending version string to an int-tuple.

iiasceri commented 1 year ago

So you need to click into the reported error file. Replace this code:

if tuple(PILversion) < (6, 2, 1): with this code:

if tuple(map(int, PILversion.split("."))) < (6, 2, 1):

lamuria commented 1 year ago

hey @bwoodsend thanks for your fix! Can we get this merged and release a new pyscreeze version? let me know if I can help in any way

iiasceri commented 1 year ago

if tuple(map(int, PILversion.split("."))) < (6, 2, 1):

david-pawlowski commented 1 year ago

I think similar to this one was already merged, but don't get why we convert to tuple instead comparing pil version string with '6.2.1' instead (6, 2, 1)

bwoodsend commented 1 year ago

Indeed, the fix slipped into https://github.com/asweigart/pyscreeze/commit/eeca245a135cf171c163b3691300138518efa64e.

but don't get why we convert to tuple instead comparing pil version string with '6.2.1' instead (6, 2, 1)

If you mean why doesn't it use PIL.__version__ >= "6.2.1" then the answer is because it gives the wrong answer whenever any of the version parts reaches a power of 10:

>>> "6.10.0" >= "6.2.1"
False