Python 3 on Fedora 24: No module named turtle (solution)

Hey guys, I ran into this issue in my programming class, and I thought I would share the solution. It's a pretty simple solution, yet it was confusing to me because I'm not quite adept with Linux yet.

[[email protected]~]$ python3
Python 3.5.2 (default, Sep 14 2016, 11:28:32) 
[GCC 6.2.1 20160901 (Red Hat 6.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'turtle'
>>> exit()

So basically, the issue was I could not import turtle graphics. I googled around and couldn't find anything about this. Eventually, I asked a teacher who informed me that I need to find a tkinter package, because Fedora and other distros often use a headless type of python, one that does not include any type of graphical interface. It never occurred to me to look for another package, because python was already installed. So I ran:

[[email protected] ~]$ dnf search python3-tk
Last metadata expiration check: 3 days, 13:53:11 ago on Sat Jan 14     20:03:06 2017.
======================================== N/S Matched: python3-tk ========================================
python3-tkinter.i686 : A GUI toolkit for Python 3
python3-tkinter.x86_64 : A GUI toolkit for Python 3
[[email protected] ~]$ sudo dnf install python3-tkinter.x86_64
[sudo] password for jim:

I simply installed the x86_64 version and that solved the problem.

3 Likes

Python has many modules that you'll have to install for some stuff to work as they are not included out of the box.

Take a look at pypi (Python Package Index) which lists many packages:

https://pypi.python.org/pypi

I usually install packages through my distros package manager but you can also use pip to install packages directly from pypi, or you could do it manually which I've had to do in the past for packages that were not available for Python 3 through pypi.

If its in the package manager thats usually the best first choice, but yes, there is pip for packages that arent int he package manager. However, for pip I would recommend you look at using python virtual environments which will keep all the pip packages within a container for the application your writing. This also means you have at least some isolation (though its not really secure isolation) from pip packages which might not be verifiable.

just a quick tip as well, installing just python3-tk will default to the architecture of your system (64bit) so you don't need to specify .x86_64 on a 64bit system (though theres no harm doing so). Its useful though if you need to install a package that isnt 64bit, for example where steam may require a 32bit library.

2 Likes

You’re the man brother! This was a fix for “no module named turtle found”.