![]() |
PIL Image im.show() no show! - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: PIL Image im.show() no show! (/thread-36300.html) |
PIL Image im.show() no show! - Pedroski55 - Feb-06-2022 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) 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. RE: PIL Image im.show() no show! - snippsat - Feb-06-2022 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()
RE: PIL Image im.show() no show! - Pedroski55 - Feb-06-2022 @ 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. RE: PIL Image im.show() no show! - Pedroski55 - Feb-06-2022 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 RE: PIL Image im.show() no show! - Pedroski55 - Feb-07-2022 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! RE: PIL Image im.show() no show! - snippsat - Feb-07-2022 (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 programmeThat'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:Using a virtualenv get the same benefited as pyenv,as don't need elevated permissions. RE: PIL Image im.show() no show! - Pedroski55 - Feb-08-2022 @snippsat Thanks! I will try to understand the tutorial! |