I use pyenv to install and manage both different versions of python and virtual environments for various projects on my system. But pipenv is the recommended tool for managing virtual environments now, and I like a lot of its features. Everything works for the most part, but pipenv seems to have a leak or something when it comes to Jupyter notebook. Here are the steps which replicate the problem on my machine.
- Install pipenv using
brew install pipenv
. - Install a new version of Python using, say,
pyenv install 3.6.3
, and activate it viapyenv global 3.6.3
. - Install Jupyter notebook and another package, e.g.
pip install jupyter requests
. - Create a new directory and navigate into it; create a pipenv project using
pipenv install
- Activate the pipenv virtual environment using
pipenv shell
. - Do not install any packages, and confirm that none are installed in the current virtualenv using
pip list
. (I only getpip
,setuptools
, andwheel
.) - Run
jupyter notebook
. My expectation: the console errors out withjupyter: command not found
. Actual: the notebook server and browser UI launch as normal. - Create a new notebook and import the auxiliary package from step 3:
import requests
. My expectation: aModuleNotFoundError
is thrown. Actual: the package is imported and can be used as normal.
If I try to import the auxiliary package in the pipenv virtual environment but outside Jupyter notebook (in the repl or in a Python script) , I get a ModuleNotFoundError
as expected. So somehow the problem is with jupyter specifically. Note that if I try to recreate this problem using a pyenv virtual environment instead of a pipenv virtual environment then the expected behavior occurs: jupyter notebook
produces a jupyter: command not found
error in the console.
My question is: am I using pipenv in a way that was not intended, or is there an alternative way to use pipenv that avoids this problem?
Thanks in advance!