These instructions are no longer up to date. Here is the updated page.

Swampy: Installation Instructions

If you have Python and Tkinter, you can install Swampy from the Python Package Index.

If you need help installing Swampy, Tkinter or Python, see the detailed instructions below. These instructions are a work in progress; if you have suggestions for improvement, let me know.

The following instructions are for Python 2. Swampy for Python 3 is available (see the bottom of this page), but it is not supported.

Once you have Swampy installed, try out some of the examples is this tutorial.

Linux

  1. Install Python

    To see if you already have Python, open a terminal (Applications->Accessories->Terminal) and type python on the Linux command line. You should see something like this:

    Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
    >>>
    

    If so, you have Python. If the version number starts with 2, you have Python 2, which is the version of Python used in Think Python. If the version number starts with 3, you have Python 3. You will not be able to use Swampy with Python 3.

    To install Python on Ubuntu, run

    sudo apt-get install python python-tk
    

    Or for Python 3

    sudo apt-get install python python3-tk
    

    Or use the Synaptic Package Manager to install "python" and "python-tk".

    For other distributions, you can find instructions at python.org. You should install the latest version of Python 2 (but anything after 2.4 should work).

  2. Install Tkinter

    To see if you have Tkinter, type python on the Linux command line. Then at the Python prompt, type

    >>> import Tkinter
    

    Or in Python 3

    >>> import tkinter
    

    If you have Tkinter, Python will not print an error message and you can go on to the next section.

    Otherwise you will see something like this:

    ImportError: No module named Tkinter
    

    In that case, you have to install Tkinter. On Ubuntu, you can run

    sudo apt-get install python-tk
    

    Or for Python 3

    sudo apt-get install python python3-tk
    
    Or use the Synaptic Package Manager to install "python-tk".

    For other distributions, you can get more information from the Tkinter wiki.

  3. Install Swampy

    To see if you have Swampy, type python on the Linux command line. Then at the Python prompt, type

    >>> import swampy.TurtleWorld
    
    If you have Swampy, Python will not print an error message and you are all set. Enjoy the book!

    Otherwise you will see something like this:

    ImportError: No module named swampy.TurtleWorld
    

    In that case, you have to install it. If you have pip installed, you can install swampy like this:

    sudo pip install swampy
    

    If that doesn't work, or you don't have pip, you can download the zip file from the Cheese Shop and and unzip it. Cd into the directory it creates and run this command:

    sudo python setup.py install
    

    If that doesn't work, try the instructions for installing packages from the Cheese Shop here.

    If you follow their instructions for Distutils, you might need to know how to "extract the distribution." Download the zip file. Make sure you are in the directory where you downloaded the file and type

    unzip swampy-*.zip
    
    Then cd into the directory it creates:
    cd swampy-x.x.x
    
    You have to replace the x's with the version number, or use tab-completion to avoid typing it.

    Finally, run the installer according to the instructions in the tutorial.

Macintosh

  1. Install Python

    According to python.org,

    Python comes pre-installed on Mac OS X, but due to Apple's release cycle, it's often one or even two years old. The overwhelming recommendation of the "MacPython" community is to upgrade your Python by downloading and installing a newer version from the Python standard release page.
    Follow these instructions to install a current version of Python. You should install the latest version of Python 2 (but anything after 2.4 should work).

  2. Install Tkinter

    To see if you have Tkinter, launch python; then at the Python prompt, type

    >>> import Tkinter
    

    Or in Python 3

    >>> import tkinter
    

    If you have Tkinter, Python will not print an error message and you can go on to the next section.

    Otherwise you will see something like this:

    ImportError: No module named Tkinter
    

    In that case, you have to install Tkinter. You can follow these instructions from python.org.

  3. Install Swampy

    To see if you have Swampy, launch python; then at the Python prompt, type

    >>> import swampy.TurtleWorld
    
    If you have Swampy, Python will not print an error message and you are all set. Enjoy the book!

    Otherwise you will see something like this:

    ImportError: No module named swampy.TurtleWorld
    

    In that case, you have to install it. If you have pip installed, you can install Swampy in a command terminal like this:

    pip install swampy
    
    Or if that doesn't work, try:
    sudo pip install swampy
    

    If that doesn't work, or you don't have pip, you can download the zip file from the Cheese Shop and and unzip it. In a command terminal,

    cd
    into the directory it creates and run this command:
    sudo python setup.py install
    

    If that doesn't work, try the instructions for installing packages from the Cheese Shop here.

    If you follow their instructions for Distutils, you might need to know how to "extract the distribution." Download the zip file. Make sure you are in the directory where you downloaded the file and type

    unzip swampy-*.zip
    
    Then cd into the directory it creates:
    cd swampy-x.x.x
    
    You have to replace the x's with the version number, or use tab-completion to avoid typing it.

    Finally, run the installer according to the instructions in the tutorial.

Windows

Thanks to Jaymie for help improving these instructions. If you have suggestions for additional improvements, please let me know.
  1. Install Python

    For instructions on running Python under Windows, see the Python Windows FAQ.

    To run Python from the Command Prompt, you need to add the folder that contains Python to the list of folders Windows searches for commands. The name of the folder is probably C:\Python26 or C:\Python27.

    To add this folder to the search path, select Control panel -> system -> advanced -> Environmental Variables -> system variables -> Path. Add C:\Python26 or C:\Python27 to the end of the list (with a semi-colon as a separator).

    Now if you restart the command window, you should be able to type python at the prompt and launch Python.

  2. Install Tkinter

    To see if you have Tkinter, launch python; then at the Python prompt, type

    >>> import Tkinter
    

    Or in Python 3

    >>> import tkinter
    

    If you have Tkinter, Python will not print an error message and you can go on to the next section.

    Otherwise you will see something like this:

    ImportError: No module named Tkinter
    

    In that case, you have to install Tkinter. You can download the ActiveTcl Community Edition from ActiveState, which should provide Tkinter. If that doesn't work, there is more general information about Tkinter here.

  3. Install Swampy

    To see if you have Swampy, launch python; then at the Python prompt, type

    >>> import swampy.TurtleWorld
    
    If you have Swampy, Python will not print an error message and you are all set. Enjoy the book!

    Otherwise you will see something like this:

    ImportError: No module named swampy.TurtleWorld
    

    In that case, you have to install it. If you have pip installed, you can install swampy like this:

    cd C:/Python/Scripts/
    pip.exe install swampy
    

    If you don't have pip, I recommend that you install it. There are instructions here.

    If you still don't have pip, you can download the Swampy zip file from the Cheese shop. Unzip it, then cd into the directory it creates and run:

    python setup.py install
    

    Again, launch Python and see if you can import swampy.TurtleWorld. If so, you are all set. If not, let me know what went wrong and I will continue to improve these instructions.

    Additional instructions for installing packages from PyPI are here.

Python 3

Swampy for Python 3 is not available as a package. But the source code is available in a zip file:

Swampy source for Python 3: swampy-2.1.5.python3.zip

The simplest way to use this code is to unzip it in your home directory, cd into the unzipped directory and work there. Or you can put it any place you like, then add the new directory to the Python search path.

Either way, you should be able to import Swampy modules, but instead of specifying the package and module like this:

from swampy.TurtleWorld import *
You would just specify the module, like this:
from TurtleWorld import *
Swampy for Python 3 is relatively new, so please let me know if you run into problems.

Back to the Swampy Home Page

Are you using Swampy in a class?

We'd like to know about it. Please consider filling out this short survey.


Think DSP

Think Java

Think Bayes

Think Python 2e

Think Stats 2e

Think Complexity