Skip to content

guilgautier/sdia-python

Repository files navigation

SDIA - Python

Python course given to students enrolled in Parcours DATA - Science des Données et Intelligence Artificielle (SDIA) managed by Pierre Chainais at Ecole Centrale de Lille.

Some material is inspired and/or borrowed from courses previously given by:

Get the project

It is suggested you Fork the original repository.

A fork is a copy of a repository that you manage. Forks let you make changes to a project without affecting the original repository. You can fetch updates from or submit changes to the original repository with Pull Requests (PRs).

  1. Fork

  2. Clone: git clone https://github.com/<your-username>/sdia-python.git

  3. Create a remote.

    cd sdia-python
    git remote -v # list the remotes ; an origin remote should be present
    git remote add upstream https://github.com/guilgautier/sdia-python.git
    git remote -v # remotes origin and upstream should be listed

This process allows you to link your local copy of <your-username>/sdia-python with the original repository guilgautier/sdia-python, so that you can fetch updates from it, e.g., corrections, new course material, etc.

git remotes

For example, at the beginning of a practical session, to get the latest course material

git checkout main # select your main branch
git pull upstream main # fetch and merge commits from guilgautier/sdia-python

Note: Merge conflicts may occur 😏. We'll see how to handle this very common situation.

Set up your working environment

We will use conda to manage Python packages and virtual environments

Virtual environment

See also notes/anaconda-vscode.md

Create a virtual environment

A virtual environment is a self-contained directory tree that contains a Python installation for a particular version of Python, plus a number of additional packages.

It is always good practice to work in a virtual environment, isolated from your other Python projects.

The environment.yml file contains the list of the main packages that will be installed when creating the environment

cd sdia-python
# conda env list
conda env create -f environment.yml

Activate a virtual environment

# cd sdia-python
conda env list
conda activate sdia-python
# prefix (sdia-python) should appear

Deactivate a virtual environment

# cd sdia-python
# conda activate sdia-python
conda deactivate
# prefix (sdia-python) should disappear

Install the project in editable mode

In order to be able to import your code in various places of your project (source files, test files, noteboooks), like

import sdia_python.lab1
from sdia_python.lab1.xxx import yyy

You can install a project in "editable" or "develop" mode while you’re working on it. When installed as editable, a project can be edited in-place without reinstallation: changes to Python source files in projects installed as editable will be reflected the next time an interpreter process is started.

Before installing the project in "editable" mode, make sure to first activate your environment,

# cd sdia-python
conda activate sdia-python # a (sdia-python) prefix should appear
pip install -e .

See also

Integrated Development Environment - Visual Studio Code

Visual Studio Code (VSCode) is recommended to ease your coding experience.

See the notes/anaconda-vscode.md file.

Jupyter Notebooks

Jupyter notebooks allow you to easily prototype code and showcase your project, see notebooks/ folder.

In order to automatically reflect modifications of the source files (located in src/) into your notebook, make sure your notebook has the following cell (make it the top cell of your notebook) and run it!

%load_ext autoreload
%autoreload 2

Launch a Jupyter notebook