Prerequisites and Assumptions

Here’s an outline of what I’m assuming about you and what you already know, as well as what software you’ll need ready and installed on your computer.

Python 3 and Programming

I’ve written the book with beginners in mind, but if you’re new to programming, I’m assuming that you’ve already learned the basics of Python. So if you haven’t already, do run through a Python beginner’s tutorial or get an introductory book like Dive Into Python or Learn Python the Hard Way, or, just for fun, Invent Your Own Computer Games with Python, all of which are excellent introductions.

If you’re an experienced programmer but new to Python, you should get along just fine. Python is joyously simple to understand.

I’m using Python 3 for this book. When I wrote it in 2013–14, Python 3 had been around for several years, and the world was just about on the tipping point at which it was the preferred choice. You should be able to follow this book on Mac, Windows, or Linux. Detailed installation instructions for each OS follow.

Tip

This book was tested against Python 3.3 and Python 3.4. If you’re on 3.2 for any reason, you may find minor differences, so you’re best off upgrading if you can.

I wouldn’t recommend trying to use Python 2, as the differences are more substantial. You’ll still be able to carry across all the lessons you learn in this book if your next project happens to be in Python 2. But spending time figuring out whether the reason your program output looks different from mine is because of Python 2, or because you made an actual mistake, won’t be time spent productively.

If you are thinking of using PythonAnywhere (the PaaS startup I work for), rather than a locally installed Python, you should go and take a quick look at Appendix A before you get started.

In any case, I expect you to have access to Python, to know how to launch it from a command line (usually with the command python3), and to know how to edit a Python file and run it. Again, have a look at the three books I recommended previously if you’re in any doubt.

Note

If you already have Python 2 installed, and you’re worried that installing Python 3 will break it in some way, don’t! Python 3 and 2 can coexist peacefully on the same system, and they each store their packages in totally different locations. You just need to make sure that you have one command to launch Python 3 (python3), and another to launch Python 2 (usually, just python). Similarly, when we install pip for Python 3, we just make sure that its command (usually pip3) is identifiably different from the Python 2 pip.

How HTML Works

I’m also assuming you have a basic grasp of how the web works—what HTML is, what a POST request is, etc. If you’re not sure about those, you’ll need to find a basic HTML tutorial—there are a few at http://www.webplatform.org/. If you can figure out how to create an HTML page on your PC and look at it in your browser, and understand what a form is and how it might work, then you’re probably OK.

JavaScript

There’s a little bit of JavaScript in the second half of the book. If you don’t know JavaScript, don’t worry about it until then, and if you find yourself a little confused, I’ll recommend a couple of guides at that point.

Required Software Installations

Aside from Python, you’ll need:

The Firefox web browser
A quick Google search will get you an installer for whichever platform you’re on. Selenium can actually drive any of the major browsers, but Firefox is the easiest to use as an example because it’s reliably cross-platform and, as a bonus, is less sold out to corporate interests.
The Git version control system
This is available for any platform, at http://git-scm.com/.
The pip Python package management tool
This comes bundled with Python 3.4 (it didn’t always used to, this is a big hooray). To make sure we’re using the Python3 version of pip, I’ll always use pip3 as the executable in my command-line examples. Depending on your platform, it may be pip-3.4 or pip-3.3. Have a look at the detailed notes for each operating system for more info.

Git’s Default Editor, and Other Basic Git Config

I’ll provide step-by-step instructions for Git, but it may be a good idea to get a bit of configuration done now. For example, when you do your first commit, by default vi will pop up, at which point you may have no idea what to do with it. Well, much as vi has two modes, you then have two choices. One is to learn some minimal vi commands (press the i key to go into insert mode, type your text, press <Esc> to go back to normal mode, then write the file and quit with :wq<Enter>). You’ll then have joined the great fraternity of people who know this ancient, revered text editor.

Or you can point-blank refuse to be involved in such a ridiculous throwback to the 1970s, and configure Git to use an editor of your choice. Quit vi using <Esc> followed by :q!, then change your Git default editor. See the Git documentation on basic Git configuration.

Required Python Packages

Once you have pip installed, it’s trivial to install new Python packages. We’ll install some as we go, but there are a couple we’ll need right from the beginning, so you should install them right away:

  • Django, sudo pip3 install django==1.8.4 (omit the sudo on Windows). This is our web framework. You should make sure you have version 1.8[2] installed and that you can access the django-admin.py executable from a command line. The Django documentation has some installation instructions if you need help.
  • Selenium, sudo pip3 install --upgrade selenium (omit the sudo on Windows), a browser automation tool that we’ll use to drive what are called functional tests. Make sure you have the absolute latest version installed. Selenium is engaged in a permanent arms race with the major browsers, trying to keep up with the latest features. If you ever find Selenium misbehaving for some reason, the answer is often that it’s a new version of Firefox and you need to upgrade to the latest Selenium…

Note

Unless you’re absolutely sure you know what you’re doing, don’t use a virtualenv. We’ll start using one later in the book, in Chapter 8.

Note

Did these instructions not work for you? Or have you got better ones? Get in touch: !



[1] I wouldn’t recommend installing Firefox via Homebrew though: brew puts the Firefox binary in a strange location, and it confuses Selenium. You can work around it, but it’s simpler to just install Firefox in the normal way.

[2] I updated the book to Django 1.8 in Spring 2015, and as it’s an LTS, this will probably be the last upgrade for a while. Make sure you install this version, even if the Django project has released a newer one since. You can always jump to the bleeding edge when you go back to your own projects!

Get Test-Driven Development with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.