Skip to content

Virtual Environment

This project environment is build using Anaconda, while the package management is done using the Python tool Poetry. The only requirement is to have anaconda installed and to be able to run commands using the conda methods in a terminal. More informations on enabling the conda method in Visual Studio Code here.

Conda

The conda environment is defined by the environment.yml file. This file contains the bare minimum to build the environment :

  • The Python version to use when creating the environment.
  • The Poetry version to load when creating the environment.
  • Any module/package which couldn't be installed using Poetry.

Poetry

The dependencies versions are defined in the pyproject.toml file. This file contains informations on the packages/modules version to use when building the environment.

Environment setup

  1. Create the virtual environment from the file environment.yml:

    conda env create --file environment.yml --prefix ./.venv
    
    $CONDA_EXE env create --file environment.yml --prefix ./.venv
    
    $CONDA_EXE

    Variable referring to the conda executable path. It should be already existing.

    conda env create

    https://docs.conda.io/projects/conda/en/latest/commands/create.html

  2. Activate the virtual environment located in ./.venv: TODO : add line about where to find the environment's name

    conda activate ./.venv
    

    Not needed.

  3. Build the environment:

    In the virtual environment:

    poetry install
    

    .venv/bin/poetry install
    
    poetry install

    https://python-poetry.org/docs/cli/#install

    Installing groups

    In the dependencies file (pyproject.toml), dependencies are organized into groups, main (nameless), dev and docs. poetry install will install all dependencies, regardless of their group.

    poetry install --only docs will only install the 'docs' group.

    poetry install --without dev,docs will install without the docs and dev groups.

  4. Run the python script hello_world.py:

    In the virtual environment:

    python hello_world.py
    

    .venv/bin/python hello_world.py
    
  5. Updating the environment:

    In the virtual environment:

    poetry update
    

    .venv/bin/poetry update
    
    poetry update

    https://python-poetry.org/docs/cli/#update

  6. Deactivate the environment:

    In the virtual environment:

    conda deactivate
    

    Not needed.