Getting the tools of the trade – Python 3.3
The first step toward using Python is getting the Python language onto our computer. If your computer uses Mac OS X or Linux, you may already have Python available. At the time of this writing, it's Python 2.7, not 3.3. In this case, we will need to install Python 3.3 in addition to Python 2.7 we already have.
Windows agents generally don't have any version of Python, and need to install Python 3.3.
Tip
Python 3 is not Python 2.7 plus a few features. Python 3 is a distinct language. We don't cover Python 2.7 in this book. The examples won't work in Python 2. Really.
Python downloads are available at http://www.python.org/download/.
Locate the proper version for your computer. There are many pre-built binaries for Windows, Linux, and Mac OS X. Linux agents should focus on the binary appropriate to their distribution. Each download and install will be a bit different; we can't cover all the details.
There are several implementations of Python. We'll focus on CPython. For some missions, you might want to look at Jython, which is Python implemented using the Java Virtual Machine. If you're working with other .NET products, you might need Iron Python. In some cases, you might be interested in PyPy, which is Python implemented in Python. (And, yes, it seems circular and contradictory. It's really interesting, but well outside our focus.)
Python isn't the only tool. It's the starting point. We'll be downloading additional tools in the later chapters. It seems like half of our job as a secret agent is locating the tools required to crack open a particularly complex problem. The other half is actually getting the information.
Windows secrets
Download the Windows installer for Python 3.3 (or higher) for your version of Windows. When you run the installer, you'll be asked a number of questions about where to install it and what to install.
It's essential that Python be installed in a directory with a simple name. Under Windows, the common choice is C:\Python33
. Using the Windows directories with spaces in their name (Program Files
, My Documents
, or Documents and Settings
) can cause confusion.
Be sure to install the Tcl/Tk components too. This will assure that you have all the elements required to support IDLE. IDLE is a handy text editor that comes with Python. For Windows agents, this is generally bundled into the installation kit. All you need to do is be sure it has a check mark in the installation wizard.
With Windows, the python.exe
program doesn't have a version number as part of its name. This is atypical.
Mac OS X secrets
In Mac OS X, there is already a Python installation, usually Python 2.7. This must be left intact.
Download the Mac OS X installer for Python 3.3 (or higher). When you run this, you will be adding a second version of Python. This means that many add-on modules and tools must be associated with the proper version of Python. This requires a little bit of care. It's not good to use the vaguely-named tool like easy_install
. It's important to use the more specific easy_install-3.3
, which identifies the version of Python you're working with.
The program named python
is usually going to be an alias for python2.7
. This, too, must be left intact. We'll always explicitly use python3
(also known as python3.3
) for this book. You can confirm this by using the shell command.
Note that there are several versions of Tcl/Tk available for Mac OS X. The Python website directs you to a specific version. At the time of this writing, this version was ActiveTCL 8.5.14 from ActiveState software. You'll need to install this, too. This software allows us to use IDLE.
Visit http://www.activestate.com/activetcl/downloads for the proper version.