13. Appendices
13.1. Installing Python
The examples and case study require [Python] 3.12 or later ([Django] 6.1 requires it). They have been tested with version 3.13.
Under [Windows], download the installer from the python.org/downloads page (the "Download Python 3.13.x" button, or a more recent version). On the first screen of the installer, check the "Add python.exe to PATH" box, which allows you to type [python] in any console, then click "Install Now." The installer also installs [pip], the [venv] module, and the [py] launcher ([py -3.13] launches a specific version when multiple versions are installed). In [Windows] 10 and 11, typing [python] without having it installed opens the Microsoft Store: this is a system shortcut that can be disabled (Settings / Apps / Advanced app settings / App launch aliases).
On [macOS], use the python.org installer or the [Homebrew] package manager: [brew install python@3.13]. Under [Linux], [Python] is already present, but the modules [venv] and [pip] are often separate packages. Under [Ubuntu] 24.04 (where the version of [Python] is 3.12):
Under [macOS] and [Linux], the commands are named [python3] and [pip3]; in an activated virtual environment, [python] and [pip] are sufficient. Verify the installation in a new console:
The first command should display a version number equal to or greater than 3.12 (for example, [Python 3.13.7]).
13.2. pip and virtual environments
[pip] is the library manager for [Python]. It downloads libraries from the [PyPI] (pypi.org) repository: an Internet connection is required during installation. If you are behind a corporate proxy, specify the proxy using the environment variables [HTTP_PROXY] and [HTTPS_PROXY], or using the [--proxy] option of [pip].
A virtual environment is a folder containing a lightweight copy of the [Python] interpreter and its own libraries: each project has its own, in the versions it requires, without affecting the [Python] installation or other projects. Useful commands in a project folder (the one containing [requirements.txt]):
Under [Windows], [PowerShell] sometimes refuses to run the activation script (“script execution is disabled on this system”): the command [Set-ExecutionPolicy -Scope CurrentUser RemoteSigned] enables it for the current user. You can also bypass activation by directly calling the environment’s interpreter: [.venv\Scripts\python manage.py runserver].
The [.venv] folder cannot be copied from one machine to another (it contains absolute paths and system-specific programs): it must be recreated using the commands above. This is why it is not included in the course materials. The [examples] folder has its own environment, shared by all 28 examples; the case study has its own.
The [mysqlclient] library and the [MySQL] driver (Example 28 and the case study) are written in C. Under [Windows], [pip] downloads a precompiled version: no action is required. Under [Linux] and [macOS], [pip] compiles it, and to do so requires the development files from [MySQL] and a compiler:
Without them, [pip install -r requirements.txt] fails on [mysqlclient], with an error message referring to [pkg-config] or [mysql_config].
13.3. Installing Visual Studio Code
[Visual Studio Code] downloads from code.visualstudio.com. Add three extensions (View menu / Extensions):
- Python (from Microsoft): for running and debugging [Python] code, and managing virtual environments. It installs the Python Debugger extension along with it;
- Pylance (from Microsoft, also installed with the Python extension): code completion, code navigation (including the code for [Django], located in the [.venv] folder), error reporting, and type annotation checking;
- Django (by Baptiste Darthenay): syntax highlighting and shortcuts for the [Django] templates ([.html] files in the [templates] folder).
Open the [examples] folder or the case study folder (File menu / Open Folder), then select the interpreter for the folder’s virtual environment (Command Palette, Ctrl+Shift+P, Python: Select Interpreter, then the one for [.venv]). The built-in terminal (Terminal menu / New Terminal) then automatically activates the environment and allows you to run applications and commands from [python manage.py ...] without leaving the editor.
To run an application step by step, create a debug configuration (Run menu / Add Configuration, then Python Debugger and Django): the editor launches [manage.py runserver] under the debugger’s control and pauses at the breakpoints set in the views.
13.4. Installing MySQL with Laragon
[Laragon] installs a ready-to-use [MySQL] server under [Windows], along with the [HeidiSQL] administration tool (see “Installing Laragon” in the introduction). After installation:
- the “Start All” button launches the [MySQL] server on port 3306;
- the user [root] has no password: these are the values from the [DATABASES] setting in Example 28 ([config/settings.py]), and the variables [DB_USER] and [DB_PASSWORD] from the [.env] file in the case study;
- the Database button opens [HeidiSQL], where the File menu / Run a File menu item (SQL) runs the scripts [dbpersons.sql] (Example 28) and [dbrdvmedecins2.sql] (case study).
In [Linux] or [macOS], install [MySQL] or [MariaDB] using the system’s package manager, and run the scripts using the command-line client [mysql] ([mysql -u root < database/dbrdvmedecins2.sql]). The [mysqlclient] driver and the [MySQL] engine from [Django] work with both without any configuration. Under [Linux], the [root] account from [MariaDB] is often configured to log in only via the system account [root] ([sudo mysql]): a user is then created for the applications:
and we specify this to the applications: the keys [USER] and [PASSWORD] from the setting [DATABASES] for Example 28, the lines [DB_USER=course] and [DB_PASSWORD=course] from the file [.env] for the case study.
13.5. Installing curl
[curl] is included with [Windows] 10 and 11, [macOS], and most [Linux] distributions. On [PowerShell], you must type [curl.exe], not [curl]: In older versions of [PowerShell], [curl] is an alias for another command ([Invoke-WebRequest]), which has different options. In the command prompt for [Windows] ([cmd]), the quotation marks for a string JSON are written as [\"] (example 11), and a string URL that contains [&] must be enclosed in double quotes.
13.6. The django-admin tool
[Django] installs a command, [django-admin], which is not required to follow this document (the examples are provided ready-to-use), but is used to start a new project. The [manage.py] file for each project is a [django-admin] file that also knows the project’s settings: within a project, you type [python manage.py] instead of [django-admin]. The most useful commands:
The period at the end of the command [startproject] creates the project in the current folder (without it, the project is created in a new folder named [config]). An application created by [startapp] must be added to the [INSTALLED_APPS] settings list. The [inspectdb] command is a valuable tool for an existing database, such as the one in the case study: it reads the tables and generates a first draft of the models using [managed = False]; all that remains is to name the relationships, choose the types, and add the methods. The commands [makemigrations] and [migrate], which create and update tables based on the models, were not used in this document: its databases are created by SQL scripts, which are shared with other versions of the application.