Python: Tkinter & turtle

Novice programmer. 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, but I get the following error:

 ImportError: No module named turtle 

After some internet research, I read that the turtle module can be found in the tkinter package. And therefore, since I have two different python installations, Python 2.7.3 and Python 3.2.3

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

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

It wasn’t me anywhere. So how can I install the missing modules for both versions of python?

Thanks!

+6
source share
6 answers

On ubuntu 16.04,

 sudo apt-get install python3-tk 

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

+5
source

To install the Tkinter module in Python 2:

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

For Python 3:

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

Although Tkinter usually ships with Python 3, the above procedure will work if the module is not installed.

+1
source

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

0
source

You tried ldconfig to make sure the libraries are "known" to the operating system. It seemed to help when I tried to make the LED blink with PiFace. In any case, it does not hurt anything and very quickly. It is worth trying IMHO. I think you need to be root for this (use sudo).

0
source

Fedora installed dnf python3-tkinter.x86_64

-2
source

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

-3
source

All Articles