Jupyter Notebook is a de facto standard for exploratory data science analysis. In this recipe, we show how to configure Jupyter with Julia.
Configuring Julia in Jupyter Notebook
Getting ready
Before installing Jupyter Notebook, perform the following steps:
-
Prepare a Linux machine with Julia installed (you can follow the instructions in the Installing Julia from binaries recipe).
-
Open a Julia console.
-
Install the IJulia package. Press ] in the Julia REPL to go to the Julia package manager and execute the add IJulia command:
(v1.0) pkg> add IJulia
How to do it...
Once IJulia is installed, there are two options for running Jupyter Notebook:
-
Running Jupyter Notebook from within the Julia console
-
Running Jupyter Notebook from bash
Running Jupyter Notebook from within the Julia environment
Simply start the Julia console and run the following commands:
julia> using IJulia
julia> notebook()
A web browser window will open with Jupyter, where you can start to work with Julia. In order to stop the Jupyter Notebook server, go back to the console and press Ctrl + C.
Running Jupyter Notebook outside of the Julia environment
In order to run Jupyter Notebook outside of Julia, firstly make sure that you have installed IJulia (see the Getting ready section). Once IJulia is installed, perform the following steps:
- Execute the shell command (this assumes that you used the default setting for the Julia packages folder; in particular the hsaaN part of the path below might be different; in such case please look-up the correct path in the ~/.julia/packages/Conda/ folder):
$ ~/.julia/packages/Conda/hsaaN/deps/usr/bin/jupyter notebook
Please note that the preceding command in Windows will look different:
C:\> %userprofile%\.julia\packages\Conda\hsaaN\deps\usr\Scripts\jupyter-notebook
- Look for console output similar to what is shown here:
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=b86b66b81a62d4be1ae34e7d6bd006a8ba5cb937e74b99cf
- Paste the link (in the preceding output marked with bold font) into your browser's address bar.
How it works...
Jupyter Notebook runs a local web server on port 8888. Once it is started, you can simply connect to it via a web browser. It is also possible to run such environments on a different machine than that used to access the notebook—please check the Jupyter in the cloud recipe for more details.
There's more...
Please note that for some packages, Julia installation might have conflicts with Windows security settings and thus prevent installation. In particular, IE Enhanced Security Configuration should be turned off (the default setting on Windows Server environments is on). In order to turn it off, open Server Manager and click Local Server, which is located on the left. In the right column, you will see the option IE Enhanced Security Configuration. Click on it to turn it off.
Another possible problem can be with the installation of IJulia, since it sometimes conflicts with an existing Python installation due to IJulia attempting to fetch and install a minimal Python environment itself. In such cases, if you get an error, run the following:
ENV["JUPYTER"] = "[path to your jupyter program]"
using Pkg
Pkg.build("IJulia")
You will have to manually find the [path to your jupyter program]. For example, on my Windows system with Anaconda installed, the path will be "C:\\Program Files\\Anaconda\\Scripts\\jupyter-notebook.exe". Note that we need to use two backslashes of the Julia string to represent a single backslash in a path. If you have provided a proper path, the build should finish successfully.
See also
The most recent documentation can be found on IJulia's website (https://github.com/JuliaLang/IJulia.jl). It is worth checking, as some details of the process described earlier may change.