If you're doing the tutorial at home

If you're doing the tutorial at home, not at one of the Django Girls events, you can completely skip this chapter now and go straight to the How the Internet works? chapter.

This is because we cover these things in the whole tutorial anyway, and this is just an additional page that gathers all of the installation instructions in one place. The Django Girls event includes one "Installation evening" where we install everything so we don't need to bother with it during the workshop, so this is useful for us.

If you find it useful, you can follow through this chapter too. But if you wanna start learning things before installing a bunch of stuff on your computer, skip this chapter and we will explain the installation part to you later on.

Good luck!

Installation

In the workshop you will be building a blog, and there are a few setup tasks in the tutorial which would be good to work through beforehand so that you are ready to start coding on the day.

Install Python

This section is based on a tutorial by Geek Girls Carrots (http://django.carrots.pl/)

Django is written in Python. We need Python to do anything in Django. Let's start with installing it! We want you to install Python 3.4, so if you have any earlier version, you will need to upgrade it.

Windows

You can download Python for Windows from the website https://www.python.org/downloads/release/python-343/. After downloading the *.msi file, you should run it (double-click on it) and follow the instructions there. It is important to remember the path (the directory) where you installed Python. It will be needed later!

One thing to watch out for: on the second screen of the installation wizard, marked "Customize", make sure you scroll down to the "Add python.exe to the Path" option and select "Will be installed on local hard drive", as shown here:

Don't forget to add Python to the Path

Linux

It is very likely that you already have Python installed out of the box. To check if you have it installed (and which version it is), open a console and type the following command:

$ python3 --version
Python 3.4.3

If you have a different 'micro version' of Python installed, e.g. 3.4.0, then you don't have to upgrade. If you don't have Python installed, or if you want a different version, you can install it as follows:

Debian or Ubuntu

Type this command into your console:

$ sudo apt-get install python3.4

Fedora (up to 21)

Use this command in your console:

$ sudo yum install python3.4

Fedora (22+)

Use this command in your console:

$ sudo dnf install python3

OS X

You need to go to the website https://www.python.org/downloads/release/python-343/ and download the Python installer:

  • Download the Mac OS X 64-bit/32-bit installer file,
  • Double click python-3.4.3-macosx10.6.pkg to run the installer.

Verify the installation was successful by opening the Terminal application and running the python3 command:

$ python3 --version
Python 3.4.3

If you have any doubts, or if something went wrong and you have no idea what to do next - please ask your coach! Sometimes things don't go smoothly and it's better to ask for help from someone with more experience.

Set up virtualenv and install Django

Part of this section is based on tutorials by Geek Girls Carrots (http://django.carrots.pl/).

Part of this section is based on the django-marcador tutorial licensed under Creative Commons Attribution-ShareAlike 4.0 International License. The django-marcador tutorial is copyrighted by Markus Zapke-Gründemann et al.

Virtual environment

Before we install Django we will get you to install an extremely useful tool to help keep your coding environment tidy on your computer. It's possible to skip this step, but it's highly recommended. Starting with the best possible setup will save you a lot of trouble in the future!

So, let's create a virtual environment (also called a virtualenv). Virtualenv will isolate your Python/Django setup on a per-project basis. This means that any changes you make to one website won't affect any others you're also developing. Neat, right?

All you need to do is find a directory in which you want to create the virtualenv; your home directory, for example. On Windows it might look like C:\Users\Name\ (where Name is the name of your login).

For this tutorial we will be using a new directory djangogirls from your home directory:

mkdir djangogirls
cd djangogirls

We will make a virtualenv called myvenv. The general command will be in the format:

python3 -m venv myvenv

Windows

To create a new virtualenv, you need to open the console (we told you about that a few chapters ago - remember?) and run C:\Python34\python -m venv myvenv. It will look like this:

C:\Users\Name\djangogirls> C:\Python34\python -m venv myvenv

where C:\Python34\python is the directory in which you previously installed Python and myvenv is the name of your virtualenv. You can use any other name, but stick to lowercase and use no spaces, accents or special characters. It is also good idea to keep the name short - you'll be referencing it a lot!

Linux and OS X

Creating a virtualenv on both Linux and OS X is as simple as running python3 -m venv myvenv. It will look like this:

$ python3 -m venv myvenv

myvenv is the name of your virtualenv. You can use any other name, but stick to lowercase and use no spaces. It is also good idea to keep the name short as you'll be referencing it a lot!

NOTE: Initiating the virtual environment on Ubuntu 14.04 like this currently gives the following error:

Error: Command '['/home/eddie/Slask/tmp/venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

To get around this, use the virtualenv command instead.

$ sudo apt-get install python-virtualenv
$ virtualenv --python=python3.4 myvenv

Working with virtualenv

The command above will create a directory called myvenv (or whatever name you chose) that contains our virtual environment (basically a bunch of directory and files).

Windows

Start your virtual environment by running:

C:\Users\Name\djangogirls> myvenv\Scripts\activate

Linux and OS X

Start your virtual environment by running:

$ source myvenv/bin/activate

Remember to replace myvenv with your chosen virtualenv name!

NOTE: sometimes source might not be available. In those cases try doing this instead:

$ . myvenv/bin/activate

You will know that you have virtualenv started when you see that the prompt in your console is prefixed with (myvenv).

When working within a virtual environment, python will automatically refer to the correct version so you can use python instead of python3.

OK, we have all important dependencies in place. We can finally install Django!

Installing Django

Now that you have your virtualenv started, you can install Django using pip. In the console, run pip install django==1.8 (note that we use a double equal sign: ==).

(myvenv) ~$ pip install django==1.8
Downloading/unpacking django==1.8
Installing collected packages: django
Successfully installed django
Cleaning up...

on Windows

If you get an error when calling pip on Windows platform please check if your project pathname contains spaces, accents or special characters (for example, C:\Users\User Name\djangogirls). If it does please consider moving it to another place without spaces, accents or special characters (suggestion is: C:\djangogirls). After the move please try the above command again.

on Windows 8 and Windows 10

Your command line might freeze after when you try to install Django. If this happens, instead of the above command use:

C:\Users\Name\djangogirls> python -m pip install django==1.8

on Linux

If you get an error when calling pip on Ubuntu 12.04 please run python -m pip install -U --force-reinstall pip to fix the pip installation in the virtualenv.

That's it! You're now (finally) ready to create a Django application!

Install a code editor

There are a lot of different editors and it largely boils down to personal preference. Most Python programmers use complex but extremely powerful IDEs (Integrated Development Environments), such as PyCharm. As a beginner, however, that's probably less suitable; our recommendations are equally powerful, but a lot simpler.

Our suggestions are below, but feel free to ask your coach what their preferences are - it'll be easier to get help from them.

Gedit

Gedit is an open-source, free editor, available for all operating systems.

Download it here

Sublime Text 2

Sublime Text is a very popular editor with a free evaluation period. It's easy to install and use, and it's available for all operating systems.

Download it here

Atom

Atom is an extremely new code editor created by GitHub. It's free, open-source, easy to install and easy to use. It's available for Windows, OSX and Linux.

Download it here

Why are we installing a code editor?

You might be wondering why we are installing this special code editor software, rather than using something like Word or Notepad.

The first is that code needs to be plain text, and the problem with programs like Word and Textedit is that they don't actually produce plain text, they produce rich text (with fonts and formatting), using custom formats like RTF (Rich Text Format).

The second reason is that code editors are specialised for editing code, so they can provide helpful features like highlighting code with colour according to its meaning, or automatically closing quotes for you.

We'll see all this in action later. Soon, you'll come to think of your trusty old code editor as one of your favourite tools :)

Install Git

Windows

You can download Git from git-scm.com. You can hit "next next next" on all steps except for one; in the 5th step entitled "Adjusting your PATH environment", choose "Run Git and associated Unix tools from the Windows command-line" (the bottom option). Other than that, the defaults are fine. Checkout Windows-style, commit Unix-style line endings is good.

MacOS

Download Git from git-scm.com and just follow the instructions.

Linux

If it isn't installed already, git should be available via your package manager, so try:

Debian or Ubuntu

$ sudo apt-get install git

Fedora (up to 21)

$ sudo yum install git

Fedora (22+)

$ sudo dnf install git

Create a GitHub account

Go to GitHub.com and sign up for a new, free user account.

Create a PythonAnywhere account

Next it's time to sign up for a free "Beginner" account on PythonAnywhere.

When choosing your username here, bear in mind that your blog's URL will take the form yourusername.pythonanywhere.com, so either choose your own nickname, or a name for what your blog is all about.

Start reading

Congratulations, you are all set up and ready to go! If you still have some time before the workshop, it would be useful to start reading a few of the beginning chapters:

Enjoy the workshop!

When you begin the workshop, you'll be able to go straight to Your first Django project! because you already covered the material in the earlier chapters.