Get and use the training source
You should already have cloned the repository of this training (Clone the repo of this training). Now it is time to use it!
Once the sources of the course are there and up-to-date, you should be able to use them:
To create the virtual environment of the training, cd in the root directory of the
training (py-edu-fr) and run
pdm syncPDM should install a Python virtual environment in the directory py-edu-fr/.venv. Let
us use the command ls .venv to see what is in this new directory.
sync, lock file and pyproject.tomlThe sync command installs a virtual environment fully described in a lock file (here
pdm.lock), which is usually versioned. The dependencies (third party Python packages)
explicitly needed for the project are listed in the file pyproject.toml. The process to
produce the lock file from the pyproject.toml file is called to “lock” the
dependencies.
This also applies to other tools like UV, Pixi and Poetry.
We can now activate the environment to use it (i.e. to use the software installed in this environment):
.venv\Scripts\activatesource .venv/bin/activateor just (in this case, the first . means source)
. .venv/bin/activateThe activation didn’t work well?
On Windows, this might result in an error related to the Restrictive Execution Policy. A solution is to run the following command in a PowerShell session started as administrator (run only this command; the activation should then be performed as a normal user in a new terminal):
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserIf you cannot do this yourself, please ask your administrator for assistance.
After activation of the environment, the command `python` should correspond to the Python
of the virtual environment. Let us check that with:
::::{tab-set}
:::{tab-item} Windows
```powershell
Get-Command python
```
:::
:::{tab-item} macOS and Linux
```sh
which python
```
:::What is the output? Does it make sense?
Note that the virtual environment can also be used without activation. In a new
terminal, cd in the root directory of the training and open a JupyterLab server with:
pdm run jupyter-labYou should now have two terminals opened:
one with the environment activated,
one running a JupyterLab server.
You should now have:
all the files used for this training:
examples and data in
py-edu-fr/src/commonnotebooks in
py-edu-fr/src/en
a virtual environment usable for the whole training (in
py-edu-fr/.venv)
In JupyterLab, navigate to the directory src/en/generalities. Note that there are .md
files (text files containing Markdown code). However, these files can also be opened as
notebooks. Right click on the file howto-use-python.md and choose “Open as notebook”.
In the terminal with the environment activated, you can open the current directory with VSCode with:
code .
# or `codium .` if you use codium
# the `.` means the current directoryIn VSCode, navigate to the directory src/common/examples and click on the file
helloworld.py.
If you have the Python extension installed, the environment of the training should be detected and used automatically.