IJulia is a Julia-language backend combined with the Jupyter interactive environment (also used by IPython). This combination allows you to interact with the Julia language using Jupyter/IPython's powerful graphical notebook, which combines code, formatted text, math, and multimedia in a single document. It also works with JupyterLab, a Jupyter-based integrated development environment for notebooks and code.
(IJulia notebooks can also be re-used in other Julia code via the NBInclude package.)
First, download Julia version 0.7
or later and run the installer. Then run the Julia application
(double-click on it); a window with a
julia> prompt will appear. At
the prompt, type:
using Pkg Pkg.add("IJulia")
to install IJulia.
This process installs a kernel specification that tells Jupyter (or JupyterLab) etcetera how to launch Julia.
Pkg.add("IJulia") does not actually install Jupyter itself.
You can install Jupyter if you want, but it can also be installed
automatically when you run
IJulia.notebook() below. (You
can force it to use a specific
jupyter installation by
ENV["JUPYTER"] to the path of the
Pkg.add, or before running
your preference is remembered on subsequent updates.
If you are comfortable managing your own Python/Jupyter installation, you can just run
jupyter notebook yourself in a terminal. To simplify installation, however, you can alternatively type the following in Julia, at the
using IJulia notebook()
to launch the IJulia notebook in your browser.
The first time you run
notebook(), it will prompt you
for whether it should install Jupyter. Hit enter to
have it use the Conda.jl
package to install a minimal Python+Jupyter distribution (via
Miniconda) that is
private to Julia (not in your
On Linux, it defaults to looking for
jupyter in your
and only asks to installs the Conda Jupyter if that fails; you can force
it to use Conda on Linux by setting
ENV["JUPYTER"]="" during installation (see above). (In a Debian or Ubuntu GNU/Linux system, install the package
jupyter-client to install the system
notebook(detached=true) to launch a notebook server
in the background that will persist even when you quit Julia.
This is also useful if you want to keep using the current Julia
session instead of opening a new one.
julia> using IJulia; notebook(detached=true) Process(`'C:\Users\JuliaUser\.julia\v0.7\Conda\deps\usr\Scripts\jupyter' notebook`, ProcessRunning) julia>
By default, the notebook "dashboard" opens in your
home directory (
homedir()), but you can open the dashboard
in a different directory with
Alternatively, you can run
from the command line (the
in MacOS or the Command
Prompt in Windows).
Note that if you installed
jupyter via automated Miniconda installer
Pkg.add, above, then
jupyter may not be in your
import Conda; Conda.SCRIPTDIR in Julia to find out where Conda
A "dashboard" window like this should open in your web browser. Click on the New button and choose the Julia option to start a new "notebook". A notebook will combine code, computed results, formatted text, and images, just as in IPython. You can enter multiline input cells and execute them with shift-ENTER, and the menu items are mostly self-explanatory. Refer to the Jupyter notebook documentation for more information, and see also the "Help" menu in the notebook itself.
Given an IJulia notebook file, you can execute its code within any other Julia file (including another notebook) via the NBInclude package.
Instead of running the classic notebook interface, you can use the IDE-like JupyterLab. If you are comfortable managing your own JupyterLab installation, you can just run
jupyter lab yourself in a terminal. To simplify installation, however, you can alternatively type the following in Julia, at the
using IJulia jupyterlab()
notebook(), above, this will install JupyterLab via Conda if it is
not installed already.
jupyterlab() also supports
dir keyword options similar to
Julia is improving rapidly, so it won't be long before you want to update to a more recent version. To update the packages only, keeping Julia itself the same, just run:
at the Julia prompt (or in IJulia).
If you download and install a new version of Julia from the Julia web
site, you will also probably want to update the packages with
Pkg.update() (in case newer versions of the packages are required
for the most recent Julia). In any case, if you install a new Julia
binary (or do anything that changes the location of Julia on your
computer), you must update the IJulia installation (to tell Jupyter
where to find the new Julia) by running
at the Julia command line (important: not in IJulia).
You can also install additional Julia kernels, for example, to
pass alternative command-line arguments to the
by using the
IJulia.installkernel function. See the help for this
? IJulia.installkernel in Julia) for complete details.
For example, if you want to run Julia with all deprecation warnings disabled, you can do:
using IJulia installkernel("Julia nodeps", "--depwarn=no")
and a kernel called
Julia nodeps 0.7 (if you are using Julia 0.7)
will be installed (will show up in your main Jupyter kernel menu) that
lets you open notebooks with this flag.
using IJulia installkernel("Julia (4 threads)", env=Dict("JULIA_NUM_THREADS"=>"4"))
env keyword should be a
Dict mapping environment variables to values.
Pkg.build()to try to rerun the install scripts.
Pkg.update()and try again: this will fetch the latest versions of the Julia packages in case the problem you saw was fixed. Run
Pkg.build("IJulia")if your Julia version may have changed. If this doesn't work, you could try just deleting the whole
.juliadirectory in your home directory (on Windows, it is called
Users\USERNAME\.juliain your home directory) via
rm(Pkg.dir(),recursive=true)in Julia and re-adding the packages.
In[*]indefinitely), try creating a new Python notebook (not Julia) from the
Newbutton in the Jupyter dashboard, to see if
1+1works in Python. If it is the same problem, then probably you have a firewall running on your machine (this is common on Windows) and you need to disable the firewall or at least to allow the IP address 127.0.0.1. (For the Sophos endpoint security software, go to "Configure Anti-Virus and HIPS", select "Authorization" and then "Websites", and add 127.0.0.1 to "Authorized websites"; finally, restart your computer.)
jupyter --versionand make sure that it prints
3.0.0or larger; earlier versions of IPython are no longer supported by IJulia.
ENV["JUPYTER"]=""; Pkg.build("IJulia")to force IJulia to go back to its own Conda-based Jupyter version (if you previously tried a different
There are various features of IJulia that allow you to interact with a running IJulia kernel.
If your code needs to detect whether it is running in an IJulia notebook
(or other Jupyter client), it can check
isdefined(Main, :IJulia) && Main.IJulia.inited.
The default Jupyter kernel that is installed by IJulia starts with the
Julia command line flag
in the folder of a notebook (or in a parent folder of this notebook) will
therefore automatically become the active project for that notebook.
Users that don't want this behavior should install an additional IJulia
kernel without that command line flag (see section
Installing additional Julia kernels).
If you want to run code every time you start IJulia---but only when in IJulia---add a
startup_ijulia.jl file to your Julia
config directory, e.g.,
One difference from IPython is that the IJulia kernel does
not use "magics", which are special commands prefixed with
%% to execute code in a different language. Instead, other
syntaxes to accomplish the same goals are more natural in Julia,
work in environments outside of IJulia code cells, and are often
However, if you enter an IPython magic command
in an IJulia code cell, it will print help explaining how to
achieve a similar effect in Julia if possible.
For example, the analogue of IPython's
%load filename in IJulia
When you are running in a notebook, ordinary I/O functions on
not function. However, you can prompt for the user to enter a string
in one of two ways:
readline(stdin) both open a
stdin> prompt widget where the user can enter a string, which is returned by
IJulia.readprompt(prompt) displays the prompt string
returns a string entered by the user.
IJulia.readprompt(prompt, password=true) does the same thing but hides the text the user types.
Analogous to the IPython.display.clear_output() function in IPython, IJulia provides a function:
to clear the output from the current input cell. If the optional
wait argument is
true, then the front-end waits to clear the
output until a new output is available to replace it (to minimize
flickering). This is useful to make simple animations, via repeated
IJulia.clear_output(true) followed by calls to
display(...) to display a new animation frame.
When Julia displays a large data structure such as a matrix, by default
it truncates the display to a given number of lines and columns. In IJulia,
this truncation is to 30 lines and 80 columns by default. You can change
this default by the
COLUMNS environment variables, respectively,
which can also be changed within IJulia via
ENV["LINES"] = 60).
(Like in the REPL, you can also display non-truncated data structures via
The new default behavior of IJulia is to truncate stdout (via
after 512kb. This to prevent browsers from getting bogged down when displaying the
results. This limit can be increased to a custom value, like 1MB, as follows
IJulia.set_max_stdio(1 << 20)
The module that code in an input cell is evaluated in can be set using
It defaults to
By default, IJulia evaluates user code using "soft" global scope, via the SoftGlobalScope.jl package: this means that you don't need explicit
global declarations to modify global variables in
for loops and similar, which is convenient for interactive use.
To opt out of this behavior, making notebooks behave similarly to global code in Julia
you can set
IJulia.SOFTSCOPE = false at runtime, or include the environment variable
environment of the IJulia kernel when it is launched.
While we strongly recommend using IPython version 3 or later (note that this
has nothing to do with whether you use Python version 2 or 3), we recognize
that in the short term some users may need to continue using IPython 2.x. You
can do this by checkout out the
ipython2 branch of the IJulia package:
Pkg.checkout("IJulia", "ipython2") Pkg.build("IJulia")
First, you will need to install a few prerequisites:
You need version 3.0 or later of IPython, or version 4 or later of Jupyter. Note that IPython 3.0 was released in February 2015, so if you have an older operating system you may have to install IPython manually. On Mac and Windows systems, it is currently easiest to use the Anaconda Python installer.
To use the IPython notebook interface, which runs in your web
browser and provides a rich multimedia environment, you will need
to install the jsonschema, Jinja2, Tornado,
and pyzmq (requires
apt-get install libzmq-dev and possibly
pip install --upgrade --force-reinstall pyzmq on Ubuntu if you are using
pip) Python packages.
(Given the pip installer,
pip install jsonschema jinja2 tornado pyzmq
should normally be sufficient.) These should have been automatically installed if you installed IPython itself
You need Julia version 0.7 or later.
Once IPython 3.0+ and Julia 0.7+ are installed, you can install IJulia from a Julia console by typing:
This will download IJulia and a few other prerequisites, and will set up a Julia kernel for IPython.
If the command above returns an error, you may need to run
retry it, or possibly run
Pkg.build("IJulia") to force a rebuild.
Most people will use the notebook (browser-based) interface, but you
can also use the IPython
or IPython terminal interfaces by running
ipython qtconsole --kernel
ipython console --kernel julia-0.7, respectively.
0.7 with whatever major Julia version you are using.)
If IJulia is crashing (e.g. it gives you a "kernel appears to have died" message), you can modify it to print more descriptive error messages to the terminal by doing:
Restart the notebook and look for the error message when IJulia dies.
(This changes IJulia to default to
verbose = true mode, and sets
capture_stderr = false, hopefully sending a bunch of debugging to
the terminal where you launched
When you are done, set
ENV["IJULIA_DEBUG"]=false and re-run
Pkg.build("IJulia") to turn off the debugging output.
1 day ago