Skip to content

13. Appendices

13.1. Installing Python

[Python] can be downloaded from python.org/downloads. The examples and case study require version 3.12 or later; they have been tested with version 3.13.

In [Windows], the installer displays the “Add python.exe to PATH” checkbox on its first screen: you must check it. The [python] command is then available in all terminals. The installer also installs the [py] launcher, which allows you to select a version when multiple versions are installed ([py -3.13]). You can also use the package manager [winget]:

winget install Python.Python.3.13

For [macOS], use the [.pkg] installer from the same page, or the [Homebrew] package manager ([brew install python@3.13]). Under [Linux], [Python] is usually already installed; check its version, and if necessary, install the [venv] module, which creates the virtual environments (under [Ubuntu]: [sudo apt install python3-venv]). Under [macOS] and [Linux], the command is often called [python3] (and [pip3]): this is the command used to create the virtual environment. Once the environment is activated, [python] and [pip] refer to those within the environment.

Verify the installation in a new console ([PowerShell], command prompt, or terminal):

python --version

which should display a version number equal to or greater than 3.12 (for example, [Python 3.13.7]). With an older version, the case study stops at startup due to a syntax error (see “Common Issues”).

13.2. Virtual Environments and pip

A virtual environment is a folder (in this case, [.venv]) that contains a copy of the [Python] interpreter and a project's libraries. Each project thus has its own, in the versions that suit it. The [examples] folder has its own environment, shared by all 28 examples; the case study has its own.

Useful commands, under [Windows] (under [Linux] and [macOS], [source .venv/bin/activate] for activation):

1
2
3
4
5
python -m venv .venv               # create the environment (once)
.venv\Scripts\activate             # activate it (in each new terminal)
pip install -r requirements.txt    # install the project libraries
pip list                           # the installed libraries
deactivate                         # deactivate the environment

[pip] downloads the libraries from the repository [PyPI] (pypi.org): an Internet connection is required during installation. If you are behind a corporate proxy, specify the proxy using the [--proxy] option in [pip]. The virtual environment cannot be copied from one machine to another (it contains absolute paths): you must recreate it using the [requirements.txt] file. This is why the [.venv] folder is not included in the course materials.

13.3. Installing Visual Studio Code

Download [Visual Studio Code] from code.visualstudio.com. Add the Microsoft Python extension (View menu / Extensions, then search for “Python”): this also installs [Pylance] (autocompletion, type checking, error reporting) and the Python Debugger. An extension like Better Jinja adds syntax highlighting to [Jinja2] views (HTML files containing {{ }} and {% %} tags).

Open the [examples] folder or the case study folder (File menu / Open Folder). The extension detects the [.venv] virtual environment and prompts you to use it: accept the prompt (you can also select it using the Python command: Select Interpreter, [Ctrl-Shift-P] keys). The built-in terminal (Terminal menu / New Terminal) then automatically activates the environment, allowing you to run applications without leaving the editor. The [F5] key, in the [app.py] file, runs the application under the debugger’s control (see “Development Mode”).

13.4. Installing MySQL with Laragon

[Laragon] (laragon.org) installs a ready-to-use [MySQL] server (or [MariaDB]) ready for use, along with the [HeidiSQL] administration tool. After installation:

  • the "Start All" button launches the [MySQL] server on port 3306;
  • the user [root] has no password: these are the default values from Example 28 ([DATABASE_URL]) and the case study ([DB_USER], [DB_PASSWORD]);
  • the Database button opens [HeidiSQL], where the File menu / Run File SQL runs the scripts [dbpersons.sql] (Example 28) and [dbrdvmedecins2.sql] (case study).

For [Linux] or [macOS], install [MySQL] or [MariaDB] using the system's package manager, and run the scripts using the command-line client [mysql]. The [PyMySQL] driver works with both without any configuration. Under [Linux], the [root] account for [MariaDB] is often configured to log in only via the system account [root] ([sudo mysql]): In this case, a user is created for the applications, and this user is specified in their configuration:

sudo mysql -e "CREATE USER 'course'@'localhost' IDENTIFIED BY 'course'; GRANT ALL ON *.* TO 'course'@'localhost';"

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 JSON string are written as [\"] (example 11), and a URL that contains [&] must be enclosed in double quotes.