[SOLVED] Missing ImageTk in python3

This forum is dedicated to basic help and support :

Ask here your questions about basic installation and usage of Mageia. For example you may post here all your questions about getting Mageia isos and installing it, configuring your printer, using your word processor etc.

Try to ask your questions in the right sub-forum with as much details as you can gather. the more precise the question will be, the more likely you are to get a useful answer

[SOLVED] Missing ImageTk in python3

Postby tarazed » Sep 26th, '15, 22:02

I have spent the day teaching myself python, specifically tkinter programming, using an online tutorial. Everything went well until images came up. On a Mageia 5 system my script was unable to import ImageTk from PIL.

First attempt at python, interactive session, showed that tkinter could not be located. Maybe python3 then; that was OK. Proceeded with the lessons. Let's try to show an image. This was the header section of the script:
Code: Select all
#!/bin/env python3

from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk

This resulted in an error message
Code: Select all
ImportError: cannot import name 'ImageTk'


From an interactive session using python it was possible to import ImageTk, but as said, no tkinter although there was a test_tkinter directory on the python2.7 hierarchy. Using python3, tkinter is available and python-pillow (PIL) supplies Image but not ImageTk. (Image handles GIF and bitmap formats only.)
Code: Select all
[lcl@belexeuli ~/python]$ locate ImageTk
/usr/lib64/python2.7/site-packages/PIL/ImageTk.py
/usr/lib64/python2.7/site-packages/PIL/ImageTk.pyc
/usr/lib64/python3.4/site-packages/PIL/__pycache__/ImageTk.cpython-34.pyc
/usr/lib64/python3.4/site-packages/PIL/__pycache__/ImageTk.cpython-34.pyo

Before that I had discovered pip and upgraded it to pip-7.1.2 then upgraded Pillow.
Code: Select all
[lcl@belexeuli ~/python]$ sudo urpmi python3-pillow
Package python3-pillow-2.6.2-2.mga5.x86_64 is already installed
[lcl@belexeuli ~/python]$ sudo pip install --upgrade Pillow
...
Successfully installed Pillow-2.9.0


So, is there a way out of this Catch-22 situation or have I messed things up by indiscriminate upgrades?
Last edited by tarazed on Sep 27th, '15, 08:35, edited 1 time in total.
tarazed
 
Posts: 273
Joined: Sep 18th, '11, 01:49

Re: Missing ImageTk in python3

Postby tarazed » Sep 26th, '15, 22:18

Perusing the documentation at http://pillow.readthedocs.org/ it appears that the module is fully developed, at least that is the impression it gives.
tarazed
 
Posts: 273
Joined: Sep 18th, '11, 01:49

Re: Missing ImageTk in python3

Postby tarazed » Sep 26th, '15, 23:13

Answering my own post again:

Poking around in the source code of python 2.7 I found a way to use tkinter, viz;
Code: Select all
#!/bin/env python

import Tkinter as tkinter
from   Tkinter import *
import ttk
from   PIL import Image, ImageTk


That allowed the script to run but it failed on the line
Code: Select all
  jpeg = ImageTk.PhotoImage( Image.open( "/home/lcl/images/creek.jpg" ) )

because there was no decoder for JPEG images. The same holds true for PNG as well. There do not appear to be any references to jpeg or png decoders or plugins in the source code tree so maybe this is simply a build problem, which would merit a bug report maybe.
Anyway, the original problem seems to be solved so I shall close this thread after an interval to wait for comments.
tarazed
 
Posts: 273
Joined: Sep 18th, '11, 01:49


Return to Basic support

Who is online

Users browsing this forum: No registered users and 1 guest