0

I am a beginning python enthusiast, self-teaching myself from the book of John Zell. I reached the point where I need to learn about objects and about graphics. So, I followed instructions and saved graphics.py into /usr/lib/python3/dist-packages

However, I got his:

import graphics Traceback (most recent call last): File "/usr/lib/python3.2/tkinter/init.py", line 40, in import _tkinter ImportError: No module named _tkinter

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/graphics.py", line 151, in import tkinter as tk File "/usr/lib/python3.2/tkinter/init.py", line 42, in raise ImportError(str(msg) + ', please install the python-tk package') ImportError: No module named _tkinter, please install the python-tk package

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3/dist-packages/graphics.py", line 153, in import Tkinter as tk ImportError: No module named Tkinter

I checked and it seems that tkinter is installed. Please kindly help me to go around it, because I dont know what to do next.

Thank you so much!

  • That script is written for Python 2. Python 2 scripts usually aren't compatible with Python 3, so you'll need to install Python 2. – Blender Jul 30 '13 at 23:46

1 Answers1

1

You problem: usr/lib/python3/dist-packages/graphics.py

line 153, in import Tkinter as tk 

In Python 3+, Tkinter is imported as tkinter. Simply edit the graphics.py file to import tkinter as tk. Note: As Bender stated, it will probably be easier to continue learning with python 2.*, as you may encounter further issues in the future.

TheoretiCAL
  • 19,461
  • 8
  • 43
  • 65
  • I doubt that's the only problem if the script is written for Python 2. – Blender Jul 30 '13 at 23:46
  • Thanks a lot for helping me out. I tried editing graphics.py file and importing it in Python 3. It did not work. Then I tried importing this module using Python 2.7. It worked, but I am frustrated I couldn't make Python 3 work for me. I really appreciate your time and efforts guys! – Stan Kolpakoff Jul 31 '13 at 03:03
  • If you really want to get it working in 3, try running 2to3 on the graphics.py file. See http://docs.python.org/release/3.0.1/library/2to3.html http://stackoverflow.com/questions/11071037/how-to-use-2to3-tool-in-windows – TheoretiCAL Jul 31 '13 at 16:50