Reputation: 7
I wanted to ask about the difference between a Jupyter notebook kernel and a Python virtual environment created through venv. From what I understand:
I made two different kernals for two different python environments so does this mean both kernals are like python environments in the jupyter lab or not.
Upvotes: 0
Views: 726
Reputation: 125
venv
itself.venv
Python and add it to your current Jupyter Kernel to add that venv. See https://stackoverflow.com/a/44072803/22692815 for more info.If you want to switch the venv of your Jupyter server, you have two choices. But first, some technical details:
Here's an analogy for this. Your Python interpreter is like a soldier on the battlefield. It is the one directly fighting the enemy, and follows orders from command. Your Jupyter Kernel is the phone that connects command to the soldier - it makes the soldier do things, but isn't a virtual environment (or soldier) itself. It is not independent, but makes it so command (your code) can control the soldier (the python interpreter). Basically:
venv
This one is easy, and it means that the default Jupyter Kernel on the new instance you launch will use the new venv. However, for the sake of this question, let's assume you don't want to do that, and instead want to be able to use this venv in your current Jupyter server.
https://stackoverflow.com/a/44072803/22692815 Here are the steps you need to add a new kernel.
jupyter_kernels
.cd
into the directory, then touch new_kernel.json
.venv
path and desired name:{
"argv": [
"/your/other/venv/bin/python3.5",
"-m",
"ipykernel",
"-f",
"{connection_file}"
],
"language": "python",
"display_name": "Your Other Kernel Name"
}
jupyter kernelspec install jupyter_kernels
or wherever the new file you created is.Upvotes: 0