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:
- Pierre-Antoine Thouvenin at Ecole Centrale de Lille - Data Science and Artificial Intelligence (SDIA), and
- Guillermo Polito at Université de Lille - M2 Data Science.
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).
-
Clone:
git clone https://github.com/<your-username>/sdia-python.git
-
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.
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.
We will use conda
to manage Python packages and virtual environments
See also notes/anaconda-vscode.md
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
# cd sdia-python
conda env list
conda activate sdia-python
# prefix (sdia-python) should appear
# cd sdia-python
# conda activate sdia-python
conda deactivate
# prefix (sdia-python) should disappear
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
- https://packaging.python.org/guides/distributing-packages-using-setuptools/#working-in-development-mode
- https://pip.pypa.io/en/latest/cli/pip_install/?highlight=editable#editable-installs
Visual Studio Code (VSCode) is recommended to ease your coding experience.
See the notes/anaconda-vscode.md file.
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
-
Within VSCode, the Jupyter extension provides a full Jupyter notebook experience within VSCode.
- Simply open a
.ipynb
file located innotebooks/
- Simply open a
-
From the command line
# cd sdia-python/notebooks # activate sdia-python jupyter notebook