We will see how to install Jupyter on different environments. We will install it on Windows, the Mac, Linux, and a server machine.Â Some consideration should be given toÂ multiple user accessÂ when installing on a server. If you are going to install it on a non-Windows environment, please review the Anaconda installation on Windows first as the same installation steps for Anaconda are availableÂ on other environments.
The Windows environment suffers from a drawback: none of the standard Linux tools are available out of the box. This is a problem as Jupyter and many other programs were developed on a version of Unix and expect many developer tools normally used in Unix to be available.
Luckily, there is a company that has seen this problem and addressed itâAnaconda. Anaconda describes itself as a Python Data Science Platform, but its platform allows for a variety of solutions in data science that are not based on Python.
After installing Anaconda and starting Navigator, you get to a dashboard that presents the programs available, such as:
The Anaconda Navigator provides access to each of the programs you have installed (using Anaconda). Each of the programs can be started from Navigator (by clicking on the associated
LaunchÂ button) and you can also start them individually (as they are standalone applications). As you install programs with Anaconda, additional menu items become available under the Anaconda menu tree for each of the applications to run directly. The menu item has coding to start the individual applications as needed.
As you can see in the preceding screen, the
Home display shows the applications available. There are additional menu choices for:
Environments:Â This menu displays all the Python packages that have been installed. I don't think R packages are displayed, nor areÂ other tools or packages included in this display.
Projects (beta): This menu is usually empty. I have been using/upgrading Anaconda for a while and have not seen anything displayed here.
Learning: This is a very useful feature, where a number of tutorials, videos, and write-ups have been included for the different applications that you (may) have installed.
Community: This lists some community groups for the different products you have installed.
The preceding screen shows Jupyter as an installed program. The standard install of Anaconda does include Jupyter.Â If you choose not to use Anaconda, you can install Jupyter directly.
Jupyter, as a project, grew out of Python, so it is somewhat dependent on which version of Python you have installed. For Python 2 installations, the command line steps to install Jupyter are:
python -m pip install --upgrade pip python -m pip install jupyter
This assumes you have
pip installed. The
pipÂ system is a package management system written in Python. To install
pip on your Windows machine, execute the following line:
python get-pip.py
As you can see, this is all Python (this code calls Python to execute a standard Python script).
Anaconda provides the tools to install a number of programs, including Jupyter. Once you have installed Anaconda, Jupyter will be available to you already.
The only issue I found was that the engine installed was Python 2 instead of Python 3. There is a process that Anaconda uses to decide which version of Python to run on your machine. In my case, I started out with Python 2. To upgrade to Python 3, I used these commands:
conda create -n py3k python=3 anaconda source activate py3k ipython kernelspec install-self
After this, when you start Jupyter, you will have the Python 3 engine choice.
You may prefer to have the Python 2 engine also available. This might be if you want to use scripts that were written using Python 2. The commands to add Python 2 back in as an engine choice are:
python2 -m pip install ipykernel python2 -m ipykernel install --user
You should now see Python 2 and Python 3 as engine choices when you start Jupyter:
Apple Macintosh provides a graphical interface that runs on the OS/X operating system. OS/X includes running BSD under the hood. BSD is a version of Unix originally developed at Berkeley. As a version of Unix, it has all the standard developer tools expected by Jupyter to install and upgrade the software; they are built-in tools.
Jupyter can be installed on the Mac using Anaconda (as before for Windows) or via the command line.
In this section, we will go through the steps for installing Jupyter on Mac.
Just as with Windows earlier, we download the latest version of Anaconda and run the installation program. One of the screens should look like this:
The Anaconda install is very typical for Mac installs: users can run the program and make sure they want to allocate so much storage for the application to install.Â
Once installed, Jupyter (and Anaconda Navigator) is available just like any other application on the system. You can run Jupyter directly, or you can launch Jupyter from the Anaconda Navigator display.
Many Mac users will prefer using the command line to install Jupyter. Using the command line, you can decide whether to install Jupyter with the Python 2 or Python 3 engine. If you want to add the Python 2 engine as a choice in Jupyter, you can follow similar steps for doing so in the earlier Windows command line installation section.
The script to install Jupyter on Mac via the command line with the Python 3 engine is:
bash ~/Downloads/Anaconda3-5.0.0-MacOSX-x86_64.sh
Similarly, the command to install with the Python 2 engine is as follows:
bash ~/Downloads/Anaconda2-5.0.0-MacOSX)
At this point, you should be able to start Jupyter with the command line and see the appropriate engine choice available:
jupyter notebook
Linux is one of the easier installations for Jupyter. Linux has all the tools required to update Jupyter going forward. For Linux, we use similar commands to those shown earlier to install on the Mac from the command line.Â
Linux is a very common platform for most programming tasks. Many of the tools used in programming have been developed on Linux and later ported to other operating systems, such as Windows.
The script to install Jupyter on Linux via the command line with the Python 3 engine is:
bash ~/Downloads/Anaconda3-5.0.0.1-Linux-x86_64.sh
Similarly, the command to install with the Python 2 engine is:
bash ~/Downloads/Anaconda2-5.0.0.1-Linux)
And, as shown earlier under specify Windows and Mac installation sections, you can have the Python 2 and Python 3 engines available using similar steps.
At this point, you should be able to start Anaconda Navigator with the command line:
anaconda-navigator
Or you can run Jupyter directly using the regular command line:
jupyter notebook
The term serverÂ has changed over time to mean several things. We are interested in a machine that will have multiple users accessing the same software concurrently. Jupyter Notebooks can be run by multiple users. However, there is no facility to separate the data for one user from another. Standard Jupyter installations only expect and account for one user. If we have a Notebook that allows for data input from the user, then the data from different users will be intermingled in one instance and possiblyÂ displayedÂ incorrectly.
See the following example in this section.
We can see an example of a collision with a Notebook that allows for data entry from a user and responds with incorrect results:
- I call upon an example that I have used elsewhere for illustration. For this example, we will use a simple Notebook that asks the user for some information and changes the display to use that information:
from ipywidgets import interact def myfunction(x): return x interact(myfunction, x= "Hello World ");
- The script presents a textbox to the user, with the original value of the box containing the
Hello Worldstring.
- As the user interacts with the input field and changes the value, the value of the variable
xin the script changes accordingly and is displayed on screen. For example, I have changed the value to the letter
A:
- We can see the multiuser problem if we open the same page in another browser window (copy the URL, open a new browser window, paste in the URL, and hit Enter). We get the exact same displayâwhich is incorrect. We expected the new window to start with a new script, just prompting us with the default
Hello Worldmessage. However, since the Jupyter software expectsÂ only one user, there is only one copy of the variable
x; thus, it displays its value
A.
We can have a Notebook server that expects multiple users and separates their instances from each other without the annoying collisions occurring. A Notebook server includes the standard Jupyter Notebook application that we have seen, but a server can also include software to distinguish the data of one user from another. We'll cover several examples of this solution in Chapter 8, Multiuser Environments.