This is going to be a quick post. I often encounter a situation when I want to test a Python third-party module, which I install into a virtual environment. And I often use Jupyter for quick tests like that. So, how do I make Jupyter use the aforementioned virtual environment in Ubuntu 16.04?
Set up the virtual environment
First, go to the folder where you’re planning to store your environment. Then create it:
I have specified the Python interpreter I want to be used, because if I don’t, it’ll set it up for Python 2. I don’t want that.
Next, activate the environment:
Now install the desired modules,
geopy in my case:
The environment is ready! Now we need to let Jupyter know about it.
Setting up the virtual environment for Jupyter
First, install the kernel module into the virtual environment:
And run the following command to set it up for Jupyter:
Opening a Jupyter notebook with the installed environment.
Now you can simply open a new notebook with the required environment:
Or switch the kernel in the existing notebook
That’s it! A very simple way to install environments and subsequently test the modules conveniently.
Thanks for dropping by! I’ll see you eventually.