In this post I will show you how to setup jupyter notebooks with pip under Windows. Also we will go through the process of creating virtual environments with pipenv and adding them to the kernel list in jupyter.
We first have to install python. Since python 2 is essentially deprecated we will go with python 3 instead. Whenever we call a command with
python in the following we mean
python3. Visit https://www.python.org/ and download the latest, stable version of python 3. Be sure to check that you do not choose to add python to your
PATH variable as this could interfere with other installations like Cygwin. Once the installation is finished create two directories in your documents folder:
PythonInstall create the following two
cmd.exe /K "cd %USERPROFILE%\Documents\PythonScripts"
jupyter notebook "%USERPROFILE%\Documents\PythonScripts"
where in both files you should replace
C:\Python3 with the base path of your python installation. The first file will start a command prompt inside your
PythonScripts folder and add the python interpreter to your
PATH variable. The second file can start jupyter once it is installed. Additionally, you can add links to these files to your python start menu folder.
We first make sure that we have a clean package environment. Start
pythoncmd.bat and run
If the output is empty you are good to go. If not run the following commands:
pip freeze > req.txt
pip uninstall -y -r req.txt
This will uninstall any previously installed packages. To install jupyter simply run
pip install jupyter --upgrade
That’s it! You can now use
jupyternotebooks.bat and start coding.
Virtual Environments with pipenv
Virtual environments give you a clean python setup. You create a virtual environment with pipenv by typing
You can use any ordinary pip command with pipenv. In order to add the current virtual environment to your jupyter kernels run
pipenv install ipykernel
This will bring up a prompt similar to
To install the kernel for jupyter notebooks run
python -m ipykernel install --user --name=my-virtualenv-name