Python Forum
Are there different versions of pillow?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Are there different versions of pillow?
#1
I made a program to watermark pdfs.
Worked great! (Past tense)

Yesterday, I also made a program to wipe out watermarks. It uses PIL. It just inspects every pixel. If the pixel is in a grey range, it paints the pixel white.
Works great!

I installed pdf2image to crack the pdf into jpgs, then look for grey colours in each jpg.

However, I noticed that, when I used pip3 to install pdf2image, it also installed pillow.

I think this must be a custom version of pillow.

Now, my beautiful watermarking program crashes with the error below. Until yesterday, it worked great!

I tried using a jpg as the watermark and that works fine, but jpg has no transparency, it covers all the text!!!

If I reinstall pillow, I think my watermarking program will work again, but maybe not my de-watermarking program.

At the moment, I am trying to install idle on and old laptop and try out my watermarking program there.

Any tips please??

Error:
enter something like purplerectangle.png or whiterectangle.png or watermark3.png this should be a .png wm16.png Traceback (most recent call last): File "./WatermarkAllpages+AllfilesV1.py", line 57, in <module> c.drawImage(pathToMergedFiles + wmfileName, x, y, width=w, height=h, mask='auto') File "/usr/lib/python3/dist-packages/reportlab/pdfgen/canvas.py", line 946, in drawImage imgObj = pdfdoc.PDFImageXObject(name, image, mask=mask) File "/usr/lib/python3/dist-packages/reportlab/pdfbase/pdfdoc.py", line 2100, in __init__ self.loadImageFromA85(src) File "/usr/lib/python3/dist-packages/reportlab/pdfbase/pdfdoc.py", line 2108, in loadImageFromA85 imagedata = pdfutils.makeA85Image(source,IMG=IMG,detectJpeg=True) File "/usr/lib/python3/dist-packages/reportlab/pdfbase/pdfutils.py", line 38, in makeA85Image raw = img.getRGBData() File "/usr/lib/python3/dist-packages/reportlab/lib/utils.py", line 886, in getRGBData annotateException('\nidentity=%s'%self.identity()) File "/usr/lib/python3/dist-packages/reportlab/lib/utils.py", line 1390, in annotateException rl_reraise(t,v,b) File "/usr/lib/python3/dist-packages/reportlab/lib/utils.py", line 144, in rl_reraise raise v File "/usr/lib/python3/dist-packages/reportlab/lib/utils.py", line 871, in getRGBData if Image.VERSION.startswith('1.1.7'): im.load() AttributeError: module 'PIL.Image' has no attribute 'VERSION' identity=[ImageReader@0x7f30b18f0e80 filename='/home/pedro/babystuff/mergedPdf/wm16.png'] pedro@pedro-512ssd:~/pdfs$
Reply
#2
you can use virtual environment to test in a clean environment (you should be using one anyway, instead of working with /installing in system install.)
pdf2image install requires pillow, but it's the standard one, even there is no version requirement. If you had pillow installed it would not install new version
Can you check what pip list what packages and versions are installed? Did you upgrade pillow lately? I guess you did at some point and it stopped working.
Image.VERSION was removed like 15 months ago, in version 6.00 (it was depreciated before that). I guess before you had version 5 of Pillow and it worked. The problem is with reportlab - they didn't change their code to reflect the change in pillow. One should report a bug.
the workaround is to downgrade your pillow to 5.4.1.


And to answer the question in the title, although it's irrelevant to your problem, there is pillow-simd, which is drop-in replacement of pillow, that claim performance improvements in certain operations. But it follows pillow 100%.

EDIT see my post - the problem is with old reportlab version. upgrade reportlab
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thanks!

I don't know what a virtual environment is, or how to get it!

I just finished installing idle in my old laptop, reportlab was already present.

I needed to get PyPDF2.

After that, I ran my watermarking program, worked great! No problems. Something is wrong with the version of pillow that pdf2image installed.

This is all for the gf! She works for an adult education agency, get a bachelor degree online. They need to provide their students a lot of old exams. Some have watermarks. Some do not have watermarks.

If she's happy, my life is better!

I'm just worried, if I reinstall pillow, the dewatermarking program will not work.
Reply
#4
(Apr-11-2020, 06:05 AM)Pedroski55 Wrote: Something is wrong with the version of pillow that pdf2image installed.
You didn't answer my question - what version of pillow is installed. As I already explained - if you had pillow installed beforehand (that was my understanding) pdf2image would not install anything. It will just check that requirement is satisfied.

To make it work:
uninstall pillow
install version 5.4.1 - last before Image.VERSION is removed. Use pip install pillow==5.4.1 and it should work. You may report bug to reportlab


about virtualenvironments - read https://docs.python.org/3/tutorial/venv.html


EDIT: Look at my next post - the problem is in reportlab being old version, no need to downgrade pillow
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Thanks again!

The version:
Quote:pedro@pedro-512ssd:~/pdfs$ pip3 install -I pillow
Collecting pillow
Using cached https://files.pythonhosted.org/packages/...x86_64.whl
Installing collected packages: pillow
Successfully installed pillow-7.1.1

I want to completely purge python from this laptop and reinstall. Something is wrong. The last 2 pdfs I de-watermarked have the pages in the wrong order.

Like I said, on my old laptop, the watermarking program works perfectly. I just ran 26 pdfs through it, no problems, using the latest version of pillow.

How can I remove all python and python modules?

I tried to force a reinstall, but it keeps installing from the cached file instead of downloading.
Reply
#6
Please, tell me what version of reportlab do you have?
In their latest version they have this line:
if getattr(Image,'VERSION','').startswith('1.1.7'): im.load()

They reflected the change in pillow in their code.
In your traceback it's a different line - from an older version:

Error:
if Image.VERSION.startswith('1.1.7'): im.load()
forget about what I said to downgrade pillow to 5.4.1. Just upgrade reportlab to latest version.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
Thanks again!

Quote:Just upgrade reportlab to latest version.

Funny, I thought of doing that about 30 minutes ago. I'm trying, but I'm in China and the connection is a bit iffy. The download keeps crashing.

I'll wait till tomorrow 5am, the net is less busy then.

I connected with a vpn, installed reportlab, now my watermark program is working on my newer laptop again!

Don't know what went wrong really, but if it works, gf is happy, so I'm happy!

Thanks for your time and advice!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020