Reputation: 5432
I am reading the book Think Python by Allen Downey. For chapter 4, one has to use a suite of modules called Swampy. I have downloaded and installed it.
The problem is that the modules were written in Python 2 and I have Python 3 (in Windows 7 RC1). When I ran the TurtleWorld module from Swampy, I got error messages about the print and exec statements, which are now functions in Python 3. I fixed those errors by including parentheses with print and exec in the code of the GUI and World modules. I also got an error that the Tkinter module could not be found. It turned out that in Python 3, the module name is spelled with a lower case t.
The third error is more difficult: ImportError: No module named tkFont.
Does anyone have any idea, please? Thank you.
Upvotes: 3
Views: 5190
Reputation: 11
FOR MAC USERS: I'm a Python newbie and came across the exact same problem. I'm writing this so others don't waste several hours trying to figure this out. Here's what you do:
Upvotes: 1
Reputation: 61
It looks like tkinter is finally catching up with Python 3 - tkFont has become tkinter.font
http://docs.pythonsprints.com/python3_porting/py-porting.html
#!/usr/bin/env python3.2
# -*- coding: utf-8 -*-
#
# font_ex.py
#
import tkinter
top = tkinter.Tk()
butt01 = tkinter.Button(top, text="Hello World", font=('Helvetica', 24,))
custom_font_serif = ('Times', 24, 'bold')
butt02 = tkinter.Button(top, text="Hello World", font=custom_font_serif)
custom_font_sans = ('Helvetica', 36, 'italic')
butt03 = tkinter.Button(top, text="Hello World", font=custom_font_sans)
butt01.pack()
butt02.pack()
butt03.pack()
top.mainloop()
Upvotes: 6
Reputation: 3744
There is a conversion tool for converting Python 2 code to work with Python 3: http://svn.python.org/view/sandbox/trunk/2to3/
Not sure how this extends to 3rd party libraries but it might be worth passing this over the swampy code.
Upvotes: 0
Reputation: 45324
Many important third-party libraries have not yet been rewritten for Python 3; you'll have to stick to Python 2.x for now. There is no way around it. As it says on the official Python download page,
If you don't know which version to use, start with Python 2.6.4; more existing third party software is compatible with Python 2 than Python 3 right now.
Upvotes: 3