Published on

The power of Pipenv and Jupyter Notebook

Table of Contents

Pipenv is a package manager for Python that simplifies package management and deployment. Jupyter Notebook is a popular tool for data science, featuring live code and visualization tools.

https://towardsdatascience.com/how-to-use-pipenv-with-jupyter-and-vscode-ae0e970df486

Here are steps to use Pipenv with Jupyter Notebook:

1. Install Pipenv

If you haven't installed Pipenv yet, you can install it using pip. Open your terminal/command prompt and enter:

pip install pipenv

2. Create a new directory for your project and initiate Pipenv

Navigate to your project folder using terminal, then initialize Pipenv:

mkdir myproject
cd myproject
pipenv --python 3.8

This will create a new virtual environment using Python 3.8. You can specify a different version of Python if you prefer.

3. Install packages

You can then install any necessary packages, such as Jupyter, using the Pipenv install command:

pipenv install jupyter

4. Run Jupyter Notebook

To run the Jupyter Notebook, first activate the virtual environment:

pipenv shell

Then, run Jupyter Notebook:

jupyter notebook

This will start the Jupyter Notebook server.

Note: There is a known issue with Jupyter finding kernels in Pipenv virtual environments. To get around this, you can make the Jupyter Notebook aware of the virtual environment with the following steps:

1. Install ipykernel in your Pipenv environment

pipenv install ipykernel

2. Add your virtual environment to Jupyter

python -m ipykernel install --user --name=myproject

Replace "myproject" with the name of your project. Now, when you start a new notebook, you should have the option to use the myproject kernel. If you select this, your notebook will have access to the packages and Python version in your Pipenv virtual environment.