Aleks
Aleks

Reputation: 111

Python: Tkinter & turtle

Beginning programmer here. From How to Think Like a Computer scientist I got the following code:

#!/usr/bin/env python3

import turtle
wn = turtle.Screen()
alex = turtle.Screen()
alex.forward(150)
alex.left(90)
alex.forward(150)

The program seems simple enough, Yet I get the following error:

ImportError: No module named turtle

After some internet research, I read that the turtle module can me found within the tkinter package. And so because I have two different python installations, Python 2.7.3 and Python 3.2.3

I ran the following commands in Ubuntu terminal, in hopes to install the missing python modules:

sudo apt-get install python-tk
sudo apt-get install python3.2-tk

It got me nowhere. So how can I install the missing modules for both versions of python?

Thanks!

Upvotes: 11

Views: 29154

Answers (6)

apb7
apb7

Reputation: 11

To setup Tkinter module in Python 2:

  • Execute sudo apt-get install python-tk in the terminal.
  • Use import Tkinter in your program.

For Python 3:

  • Execute sudo apt-get install python3-tk in the terminal.
  • Use import tkinter in your program.

Although Tkinter usually comes bundled up with Python 3, the above procedure will work incase the module is not installed.

Upvotes: 1

user3661564
user3661564

Reputation: 107

For Fedora is dnf install python3-tkinter.x86_64

Upvotes: -2

Fangxing
Fangxing

Reputation: 6115

On ubuntu 16.04,

sudo apt-get install python3-tk

solved my problem, if this not work for you, see this question too Tkinter module not found on Ubuntu

Upvotes: 10

thinkinggorilla
thinkinggorilla

Reputation: 31

Installing python3-tk should solve your problem. I had the same problem on my ubuntu12.04 pc, solved it by installing python3-tk. This installs the tkinter module for python3 as you are executing your code on python3 only (#!/usr/bin/env python3).

Upvotes: 0

tsegay
tsegay

Reputation: 1

Use from turtle import Turtle to import the turtle module, instead of import turtle.

Upvotes: -3

zaken
zaken

Reputation: 1

Have you tried an ldconfig to make sure the libraries are "known" to operating system. Seemed to help when I was trying to get LED's to flash with PiFace. Anyway, it wont hurt anything and is very quick. So worth a try IMHO. I think you need to be root (use sudo) to do that.

Upvotes: 0

Related Questions