Is there a way to use pipenv with Jupyter notebook?

Question:

Is there a way to use pipenv with Jupyter notebook?

Or more specifically, with an atom nteract/hydrogen python 3 kernel?

Asked By: emehex

||

Answers:

Just tried the following with success.

In your project folder:

pipenv install ipykernel
pipenv shell

This will bring up a terminal in your virtualenv like this:

(my-virtualenv-name) bash-4.4$

In that shell do:

python -m ipykernel install --user --name=my-virtualenv-name

Launch jupyter notebook:

jupyter notebook

In your notebook, Kernel -> Change Kernel. Your kernel should now be an option.

Change Kernel Screenshot

Source: IPythonNotebookVirtualenvs

Answered By: Luis Meraz

Luis’ answer works perfectly for jupyter notebooks.

But for hydrogen/atom specifically the recipe is:

pipenv install ipykernel
pipenv shell

launch atom from within the pipenv shell

> atom

Should be good to go!

Answered By: emehex

Install and start jupyter inside pipenv:

pipenv install jupyter
pipenv run jupyter notebook

Any other packages that are installed via pipenv (e.g. pipenv install numpy) will also be available to your jupyter notebook session.

Answered By: dahe

My answer is based on previous answers, but I found one more step was necessary (pipenv install notebook). So in total:

Step 1. On terminal, first install both jupyter and (jupyter) notebook. In my experience, the latter had to be explicitly installed:

pipenv install jupyter notebook

Step 2. Install the Pipenv kernelspec for jupyter (modified from u-phoria’s comment).

pipenv run python -m ipykernel install --user --name=`basename $VIRTUAL_ENV`

Now the following should work:

pipenv run jupyter notebook

Note: If in the Pipenv shell for the virtual environment, pipenv run can be removed from the above. If Pipenv is being forced to ignore virtual environments, the run commands should be run in the shell for the environment

For the original question of using Atom, it can then be run by this pipenv:

pipenv run atom
Answered By: GSB
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.