How to Avoid Environment Conflicts in Jupyter Notebooks
Dependency conflicts no more.
As developers, we have all spent many hours debugging one thing: dependency conflicts.
Here I will provide a 1 minute tutorial that will save you hours later by setting up a separate environment per notebook. This way each notebook will not self-destruct when we perform any environment updates such as pip install
a new package.
First, we start by creating a new environment and activate it.
python -m venv flux_env
source flux_env/bin/activate
Then, we will install the base environment in OpenVINO Notebooks as usual:
python -m pip install --upgrade pip
pip install -r openvino_notebooks/requirements.txt
Lastly, here we attach this new environment as a new kernel
python -m ipykernel install --user --name=flux_env
That will create a new folder here
/home/raymondlo84/.local/share/jupyter/kernels/flux_env
, and a kernel.json
file.
#"~/.local/share/jupyter/kernels/flux_env/kernel.json"
{
"argv": [
"/home/raymondlo84/flux_env/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "flux_env",
"language": "python",
"metadata": {
"debugger": true
}
}
When you run OpenVINO Notebooks with Jupyter, you will see a new kernel in that list. Now you select that before you run any code. That’s it. All changes such as pip install
will be contained within the kernel (flux_env
) and no longer shared across all notebooks.
Happy coding!