Store conda environment package list inside Notebook documents
Project description
Store conda environment package list inside Notebook documents
This package provides a hook for the Jupyter Notebook that saves metadata about the conda environment (equivalent of conda env export) inside the Notebook .ipynb file everytime that the Notebook is saved. It also supports packages installed inside the conda environment with pip.
Once such Jupyter Notebook is shared, another user can inspect the environment where it ran:
$ nbenv --extract my_notebook.ipynb
name: test_input_env
channels:
- defaults
- conda-forge
dependencies:
- ca-certificates=2017.08.26=h1d4fec5_0
- certifi=2017.7.27.1=py35h19f42a1_0
- decorator=4.1.2=py35h3a268aa_0
- ipykernel=4.6.1=py35h29d130c_0
- ipython=6.1.0=py35h1b71439_1
- ipython_genutils=0.2.0=py35hc9e07d0_0
- jupyter_client=5.1.0=py35h2bff583_0
- pip:
- ipython-genutils==0.2.0
- jupyter-client==5.1.0
And re-create the same environment (includes install of IPython Kernel):
$ nbenv my_notebook.ipynb --name reconstructed_env
$ source activate reconstructed_env
$ jupyter notebook
The environment metadata will be preserved if the Notebook file is modified by a Jupyter Notebook session with no nbenv installed.
Install
Install the package with pip install nbenv
Install the Jupyter Notebook hook in your .jupyter/jupyter_notebook_config.py:
try:
from nbenv import save_conda_environment
c.FileContentsManager.pre_save_hook = save_conda_environment
except ImportError:
print("nbenv package not found: automatic saving of conda environment disabled")
Implementation details
The pre_save_hook is automatically triggered by the Jupyter Notebook before saving the Notebook to disk. It identifies the conda environment being run checking the KernelSpec and then calls conda env export and saves the output in ["content"]["metadata"]["conda_environment"] in the .ipynb JSON.
The nbenv command line tool can then extract that and use conda create to a new environment.
Credits
Design of this package was conceived during discussion at the Container Analysis Environments Workshop held at NCSA in August 2017.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nbenv-0.1.4.tar.gz
.
File metadata
- Download URL: nbenv-0.1.4.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6f08fcde34b7174d982eebcee0f150bc9c25a7b8a15298493900c2f2aab12b3 |
|
MD5 | 97f2d0c8a5f06956695729e429281d05 |
|
BLAKE2b-256 | 8b0d0d1581bd19287db3719f09eace46003745ab60f62440cbd220d760853c07 |
File details
Details for the file nbenv-0.1.4-py2.py3-none-any.whl
.
File metadata
- Download URL: nbenv-0.1.4-py2.py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bfcd770cc75bf9bb5968af692a79ce4a5042b996b89737027c118176ff8c88f |
|
MD5 | c52fb5fc58cffe7a2affc4b2a3b2f4dd |
|
BLAKE2b-256 | 8e66aa85ce2824db43850e9e92c97c812698feb0d735d5c48b95c146c69c5182 |