If you're doing the tutorial at home
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 this chapter too. But if you want to 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.
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.
You can skip right over this section if you're not using a Chromebook. If you are, your installation experience will be a little different. You can ignore the rest of the installation instructions.
Cloud 9 is a tool that gives you a code editor and access to a computer running on the Internet where you can install, write, and run the software. For the duration of the tutorial, Cloud 9 will act as your local machine. You'll still be running commands in a terminal interface just like your classmates on OS X, Ubuntu, or Windows, but your terminal will be connected to a computer running somewhere else that Cloud 9 sets up for you.
- Install Cloud 9 from the Chrome web store
- Go to c9.io
- Sign up for an account
- Click Create a New Workspace
- Name it django-girls
- Select the Blank (second from the right on the bottom row with orange logo)
Now you should see an interface with a sidebar, a big main window with some text, and a small window at the bottom that looks something like this:
This bottom area is your terminal, where you will give the computer Cloud 9 has prepared for your instructions. You can resize that window to make it a bit bigger.
A virtual environment (also called a virtualenv) is like a private box we can stuff useful computer code into for a project we're working on. We use them to keep the various bits of code we want for our various projects separate so things don't get mixed up between projects.
In your terminal at the bottom of the Cloud 9 interface, run the following:
sudo apt update sudo apt install python3.6-venv
If this still doesn't work, ask your coach for some help.
mkdir djangogirls cd djangogirls python3.6 -mvenv myvenv source myvenv/bin/activate pip install django~=2.0.6
(note that on the last line we use a tilde followed by an equal sign: ~=).
Make a GitHub account.
The Django Girls tutorial includes a section on what is called Deployment, which is the process of taking the code that powers your new web application and moving it to a publicly accessible computer (called a server) so other people can see your work.
This part is a little odd when doing the tutorial on a Chromebook since we're already using a computer that is on the Internet (as opposed to, say, a laptop). However, it's still useful, as we can think of our Cloud 9 workspace as a place for our "in progress" work and Python Anywhere as a place to show off our stuff as it becomes more complete.
Thus, sign up for a new Python Anywhere account at www.pythonanywhere.com.
For readers at home: this chapter is covered in the Installing Python & Code Editor video.
This section is based on a tutorial by Geek Girls Carrots (https://github.com/ggcarrots/django-carrots)
Django is written in Python. We need Python to do anything in Django. Let's start by installing it! We want you to install Python 3.6, so if you have any earlier version, you will need to upgrade it.
First check whether your computer is running a 32-bit version or a 64-bit version of Windows, by pressing the Windows key + Pause/Break key which will open your System info, and look at the "System type" line. You can download Python for Windows from the website https://www.python.org/downloads/windows/. Click on the "Latest Python 3 Release - Python x.x.x" link. If your computer is running a 64-bit version of Windows, download the Windows x86-64 executable installer. Otherwise, download the Windows x86 executable installer. After downloading the installer, you should run it (double-click on it) and follow the instructions there.
One thing to watch out for: During the installation, you will notice a window marked "Setup". Make sure you tick the "Add Python 3.6 to PATH" checkbox and click on "Install Now", as shown here:
In upcoming steps, you'll be using the Windows Command Line (which we'll also tell you about). For now, if you need to type in some commands, go to Start menu and enter "Command Prompt" into the search field there. (On older versions of Windows, you can start the Command Line with Start menu → Windows System → Command Prompt.) You can also hold in the Windows key and press the "R"-key until the "Run" window pops up. To open the Command Line, type "cmd" and press enter in the "Run" window.
Note: if you are using an older version of Windows (7, Vista, or any older version) and the Python 3.6.x installer fails with an error, you can try either:
- install all Windows Updates and try to install Python 3.6 again; or
- install an older version of Python, e.g., 3.4.6.
If you install an older version of Python, the installation screen may look a bit different than shown above. Make sure you scroll down to see "Add python.exe to Path", then click the button on the left and pick "Will be installed on local hard drive":
Note Before you install Python on OS X, you should ensure your Mac settings allow installing packages that aren't from the App Store. Go to System Preferences (it's in the Applications folder), click "Security & Privacy," and then the "General" tab. If your "Allow apps downloaded from:" is set to "Mac App Store," change it to "Mac App Store and identified developers."
You need to go to the website https://www.python.org/downloads/release/python-361/ and download the Python installer:
- Download the Mac OS X 64-bit/32-bit installer file,
- Double click python-3.6.1-macosx10.6.pkg to run the installer.
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.6.1
If you have a different 'micro version' of Python installed, e.g. 3.6.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:
Verify the installation was successful by opening a command prompt and running the
$ python3 --version Python 3.6.1
NOTE: If you're on Windows and you get an error message that
python3 wasn't found, try using
python (without the
3) and check if it still might be a version of Python 3.6.
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 (https://github.com/ggcarrots/django-carrots).
Part of this section is based on the django-marcador tutorial licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. The django-marcador tutorial is copyrighted by Markus Zapke-Gründemann et al.
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
Name is the name of your login).
NOTE: On Windows, make sure that this directory does not contain accented or special characters; if your username contains accented characters, use a different directory, for example,
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
To create a new
virtualenv, you need to open the command prompt and run
python -m venv myvenv. It will look like this:
C:\Users\Name\djangogirls> python -m venv myvenv
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!
We can create a
virtualenv on both Linux and OS X by 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 a good idea to keep the name short as you'll be referencing it a lot!
NOTE: On some versions of Debian/Ubuntu you may receive the following error:
The virtual environment was not created successfully because ensurepip is not available. On Debian/Ubuntu systems, you need to install the python3-venv package using the following command. apt install python3-venv You may need to use sudo with that command. After installing the python3-venv package, recreate your virtual environment.
In this case, follow the instructions above and install the
$ sudo apt install python3-venv
NOTE: On some versions of Debian/Ubuntu initiating the virtual environment 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
$ sudo apt install python-virtualenv $ virtualenv --python=python3.6 myvenv
NOTE: If you get an error like
E: Unable to locate package python3-venv
then instead run:
sudo apt install python3.6-venv
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).
Start your virtual environment by running:
NOTE: on Windows 10 you might get an error in the Windows PowerShell that says
execution of scripts is disabled on this system. In this case, open another Windows PowerShell with the "Run as Administrator" option. Then try typing the following command before starting your virtual environment:
C:\WINDOWS\system32> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned Execution Policy Change The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A
Start your virtual environment by running:
$ source myvenv/bin/activate
Remember to replace
myvenv with your chosen
sourcemight 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
When working within a virtual environment,
python will automatically refer to the correct version so you can use
python instead of
OK, we have all important dependencies in place. We can finally install Django!
Now that you have your
virtualenv started, you can install Django.
Before we do that, we should make sure we have the latest version of
pip, the software that we use to install Django:
(myvenv) ~$ python3 -m pip install --upgrade pip
Installing packages with requirements
A requirements file keeps a list of dependencies to be installed using
First create a
requirements.txt file inside of
djangogirls/requirements.txt file you should add the following text:
pip install -r requirements.txt to install Django.
(myvenv) ~$ pip install -r requirements.txt Collecting Django==2.0.6 (from -r requirements.txt (line 1)) Downloading Django-2.0.6-py3-none-any.whl (7.1MB) Installing collected packages: Django Successfully installed Django-2.0.6
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 using another place without spaces, accents or special characters (suggestion:
C:\djangogirls). Create a new virtualenv in the new directory, then delete the old one and try the above command again. (Moving the virtualenv directory won't work since virtualenv uses absolute paths.)
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 is an open-source, free editor, available for all operating systems.
Sublime Text 3
Sublime Text is a very popular editor with a free evaluation period and it's available for all operating systems.
Atom is an extremely new code editor created by GitHub. It's free, open-source and available for Windows, OS X and Linux.
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 reason 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 specialized for editing code, so they can provide helpful features like highlighting code with color 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 favorite tools. :)
Git is a "version control system" used by a lot of programmers. This software can track changes to files over time so that you can recall specific versions later. A bit like the "track changes" feature in Microsoft Word, but much more powerful.
You can download Git from git-scm.com. You can hit "next" on all steps except for one; in the step entitled "Adjusting your PATH environment", choose "Use Git and optional Unix tools from the Windows Command Prompt" (the bottom option). Other than that, the defaults are fine. Checkout Windows-style, commit Unix-style line endings is good.
Do not forget to restart the command prompt or powershell after the installation finished successfully.
Create a GitHub account
Go to GitHub.com and sign up for a new, free user account.
Create a PythonAnywhere account
Sign up for a free "Beginner" account on PythonAnywhere:
Note When choosing your username here, bear in mind that your blog's URL will take the form
yourusername.pythonanywhere.com, so choose either your own nickname or a name for what your blog is all about.
Creating a PythonAnywhere API token
This is something you only need to do once. When you've signed up for PythonAnywhere, you'll be taken to your dashboard. Find the link near the top right to your "Accounts" page, then select the tab named "API token", and hit the button that says "Create new API token".
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.