More often than not, to accomplish a task you need several tools (i.e. software), and according to the task itself, you need specific tools.
Solving different tasks will lead you to continuously add new software that increase the probability of software conflicts.
Creating an environment for each task (or small group of heterogeneous tasks) will help to avoid software conflicts.
conda
is the tool to easily manage environments.
First of all you need to install the package manager. I suggest to use miniforge.
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" bash Miniforge3-$(uname)-$(uname -m).sh
miniforge3/bin/mamba init
As an alternative you can use the installer tailored for the Virtual Machines @UniMiB:
wget https://raw.githubusercontent.com/qLSLab/CBCourse/main/VMconfigs/installMyMamba.sh
and then execute it from the home
To create a new environment is simple as this:
mamba create -n MyEnvironmentName
then you need to activate it
mamba activate MyEnvironmentName
and populate it with the available software of your choice
mamba install python=3.11 pandas matplotlib
With the line above, you will install python (version 3.11), its two libraries matplotlib and pandas, with all the necessary programs (dependencies).
From now on, whenever you need to use python together with pandas or matplotlib, it is enough to activate de environment and use them.
Remember that the programs installed within an environment are available only within that environment.
To "enter" an environment you need to explicitly activate it:
mamba activate environmentName
Once finished, you can "exit" the environment by deactivating it:
mamba deactivate
To obtain the list of all the available environments, digit
mamba info --envs
It is possible to save a snapshot of an environment in order to share it, or to port it on another computer.
mamba activate MyEnvironmentName
mamba env export > environment.yml
then, you can create an exact copy of it running
conda env create -f environment.yml
or
mamba env update -n <your-env> --file environment.yml
To completely remove an environment from your computer, digit
mamba env remove --name MyEnvironmentName
A conda/mamba channel is a compilation of packages. Some of them are thematics such as bioconda
or tries to have the most up to date
cross platform version of the packages conda-forge
To add a channel to an environment run
mamba config --append channels conda-forge
Create an environment to perform exploratory data analyses with python. Let's say we need python (3.11), ipython (to ease the use of python), pandas (to mangle the data), openpyxl (to write *.xlsx) and matplotlib to visualize the information.
mamba create -n dataAn python=3.11
mamba activate dataAn
mamba install ipython pandas openpyxl matplotlib
or from the file condaEnvDataAnalysisMinimal.yml
conda create -f condaEnvDataAnalysisMinimal.yml
-
If not already done, install miniforge or micromamba:
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" bash Miniforge3-$(uname)-$(uname -m).sh
miniforge3/bin/mamba init
-
Create a new specific environment for your project:
mamba create -n myNewProjectEnv python=3.XX poetry="1.*"
-
activate it:
mamba activate myNewProjectEnv
-
create a new project
poetry new myNewProject
or tune thepyproject.toml
-
Install all the dependencies
poetry install
-
run your code either from mamba or poetry e.g
poetry run ipython myProgram.py
- to render invisible charaters
"editor.renderWhitespace": "all",
(ctrl,
-> searchwhitespace
) - Select and activate an environment