Python Forum
PIL Image im.show() no show!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIL Image im.show() no show!
#1
For my little OMR programme, I need to crop the image I have into columns. Normally this works no problem.

The image is an A4 size .jpg. The 'bubbles' for each question are in rows and, in this case, 2 columns.

I have done this many many times. I keep entering coordinates for cropping, top left, bottom right, until I get what I want, then save the crop-coordinates.

Today something weird is wrong.

I load an image in /home/pedro/summer2022/OMR/20BE/pdf2jpg/20BE11.jpg to get the crop coordinates.

from PIL import Image, ImageOps
image = '/home/pedro/summer2022/OMR/20BE/pdf2jpg/20BE11.jpg'
Image opens the jpg, and im is the correct size, A4

Quote:>>> im = Image.open(image)
>>> im
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=1654x2339 at 0x7FB3AA6ABA30>

but when I try im.show()

Quote:>>> im.show()

I get "No images found in "file:///tmp/tmpw6yxazsp.PNG" (I can't see how to post the screenshot of the image of the output window, but that's what it says.)

This has always worked without a hitch!

Any clues as to what may be wrong? I guess an update changed something. A permissions thing??

I tried another Python programme I have to make little 5 question answer forms. Same problem, can't get the coordinates. Has always worked.
Reply
#2
There is nothing wrong with code,but when try to load image from temp location it fail.
Try to do all in interactive shell or all as code .py,now it look like you run to first line outside of shell.
Quick test both work.
(sc_env) tom@tom-VirtualBox:~/sc_env$ python
Python 3.10.2 (main, Jan 31 2022, 15:25:53) [GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image, ImageOps
>>> 
>>> image = '/home/tom/sc_env/images_icons_linux-bsd.gif'
>>> im = Image.open(image)
>>> im
<PIL.GifImagePlugin.GifImageFile image mode=P size=32x32 at 0x7F3FE666D630>
>>> im.show()
As code.
# im_test.py
from PIL import Image, ImageOps

image = '/home/tom/sc_env/images_icons_linux-bsd.gif'
im = Image.open(image)
im.show()
Output:
(sc_env) tom@tom-VirtualBox:~/sc_env$ python im_test.py (sc_env) tom@tom-VirtualBox:~/sc_env$ # show the image
Reply
#3
@ snippsat: I did this all in the Python Idle shell. I was making a new OMR module for 4 classes.

Like I said, this has always worked before.

I think I know what may have caused the problem, but not yet how to fix it.

Recently, I wanted to get some text from a pdf. PyPDF2 could not get the text.

Not long ago, you mentioned pdfplumber. I copied your examples and saved them.

I installed pdfplumber. I got the text I wanted with pdfplumber.

I noticed when pdfplumber was installing, that it installed a version of PIL.

I already had PIL installed, because my little OMR programme needs it.

Somehow there is a clash.
Reply
#4
Also, just to test this, I started Idle as sudo
Then there is no problem, the image opens as it should.

Quote:>>> from PIL import Image, ImageOps
>>> path2jpg = '/home/pedro/Pictures/Ares-Statue.jpg'
>>> im = Image.open(path2jpg)
>>> im.show()
>>>
Reply
#5
I still don't know what was wrong, but I made a Virtual Environment just for my OMR programme.

I only installed the modules which I really needed (apart from built-ins).

After that, everything worked!
Reply
#6
(Feb-07-2022, 08:28 AM)Pedroski55 Wrote: I still don't know what was wrong, but I made a Virtual Environment just for my OMR programme
That's the way to go to avoid sudo(usage)/permission problems.
virtualenv does not need elevated permissions

It's very common problem and sudo pip install it's not safe and it's being frowned upon.
Can use this pip install --user <packagename>,but then have to remember to always use --user flag.

In my tutorial pyenv Simple Python Version Management which is way to install Python and avoid these problems.
Quote:
  • No more using python3 or pip3 or sudo or --user when pip install something.
  • It's always python and pip to version set as global,eg pip install requests to global version.
Using a virtualenv get the same benefited as pyenv,as don't need elevated permissions.
Pedroski55 likes this post
Reply
#7
@snippsat Thanks! I will try to understand the tutorial!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  encode/decode to show correct country letters in a CTk combobox janeik 2 729 Sep-02-2023, 09:46 AM
Last Post: janeik
  PDF properties doesn't show created or modified date Pedroski55 4 1,102 Jun-19-2023, 08:09 AM
Last Post: Pedroski55
  Multiple.ui windows showing at the same time when I only want to show at a time eyavuz21 4 1,038 Dec-20-2022, 05:14 AM
Last Post: deanhystad
  How to get cell(x,y).value = "\'=name(p)" to show correctly ?? ozlevia 9 3,473 Oct-31-2022, 06:47 PM
Last Post: deanhystad
  Why doesn't it show me anything in print? Melcu54 2 931 Oct-01-2022, 12:07 AM
Last Post: snippsat
  PIL Image im.show() no show! Pedroski55 2 978 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
Question Trouble installing modules/libraries and getting Notepad++ to show cyrillic letters Dragiev 6 2,272 Jul-24-2022, 12:55 PM
Last Post: Dragiev
  python basemap, cant show the right coordinates dbsr 0 968 Jun-08-2022, 01:55 PM
Last Post: dbsr
  Make console show after script was built with Pyinstaller --NOCONSOLE? H84Gabor 0 1,217 May-05-2022, 12:32 PM
Last Post: H84Gabor
  I cannot install this library. Can someone show me how? Led_Zeppelin 8 5,921 Mar-12-2021, 05:17 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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