Package: venv-kernel
venv-kernelSummaryThis package creates jupyter kernels for thevenvit is installed
in.Use-case scenarioYou maintain multiple virtual environments via python'svenvor thevirtualenvpackage. You want
to be able to switch between them from within asinglejupyter
installation. How do you do this?You need a (user-) global jupyter installation. The recommended
approach for that is to usepipxto install jupyter as a standalone
tool. Jupyter can handle multiple different kernels, even for the same
python version, and they are easily maintained with thejupyter kernelspeccommand. The only nuissance is to create and install the
kernel.json files manually for each venv. That's wherevenv-kernelcomes in.Suggested workflowOne-time setupIt is recommended to maintain your python versions withpyenvand
jupyter withpipx. Both of these packages can be installed with the
usual package managers such asapt-getorbrew.Specifically, install and temporarily activate a recent python version
with pyenv, e.g., viapyenv install 3.9.10
pyenv shell 3.9.10Then install jupyter using pipx as perpipx install --install-deps notebook jupyter jupyter_contrib_nbextensionswhich places it in its own virtual environment, all managed by
pipx. You can call jupyter from the command line now.Install a custom kernel for a VENVEvery time you want to add a custom virtual environment as a kernel
option to your jupyter notebook server, follow these steps:If you haven't done so yet, create and activate the venv as per usual, e.g., viapyenvshell3.10# we want to use this particular python versionpip-mvenv.venv
..venv/bin/activate
pipinstall--upgradepip
pipinstall<listofpackageshere>orpipinstall-rrequirements.txtInstall venv-kernel as perpipinstallvenv-kernelCreate and install the custom jupyter kernelvenv-kernelinstall--name"MyProject"--description"Virtual Environment for MyProject using Python 3.10"Here the--nameand--descriptionare optional and default
to the direcory name of the virtual environment.Start/restart your jupyter notebook server. You should now see the
kernel "MyProject", which uses the Python version of your virtual
environment and has access to all the packages installed in it.RemovalIf for any reason you want to uninstall a kernel created by this
package, you can simply do so using the commandsjupyterkernelspeclistto identify the kernel in question
and then delete it viajupyterkernelspecremoveIf you are within a virtualenv that hasvenv-kernelinstalled, you
can also usevenv-kernellistto see if there's currently a kernel installed that corresponds to the current venv, andvenv-kernelcleanto remove it.Similar packagesThere are other packages that provide similar or related
functionality, and these may or may not serve your purposes better
than this package, which is designed solely to meet the author's
needs. These packages include:callisto: Create jupyter kernels from virtual environmentsenvkernel: Jupyter kernels manipulation and in other environments (docker, Lmod, etc.)ssh-ipykernel: A remote jupyter ipykernel via sshMIT LicenseCopyright 2021-2024 Björn RüfferPermission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.