Skip to content

oschulz/julia-course

Repository files navigation

Introduction to Julia

This course currently constists of

You need both Julia and a way to run Jupyter notebooks to run this course.

Installing Julia and either Jupyter or nteract

Installing Julia

Julia is easy to install:

  • Download Julia.

  • Extract the archive resp. run the installer.

  • You may want to add the Julia "bin" directory to your $PATH"

We highly recommend using Julia v1.9 to run the code in this course.

Installing Jupyter

If you have a working Jupyter installation, it should detect the Jupyter Julia kernel (see below on how to install it) automatically.

You can also start Jupyter via Julia: This can either use existing installations of Jupyter, or install both internally by creating an internal Conda installation within $HOME/.julia/conda. On Linux, Julia will by default to use the Jupyter installation associated with the jupyter executable on your $PATH. On OS-X and Windows, both IJulia will by default always create a Julia-internal Conda installation (see above). To change this behavior, set the environment variable $JUPYTER. For details, see the IJulia.jldocumentation.

Note: This course doesn't call on any Python packages from Julia. If you do call Python from Julia though (e.g. indirectly via packages like PyPlot.jl and UltraNest.jl or directly via PyCall.jl), the same default behavior occurs (the system's Python3 is used on Linux, a Julia-internal Conda environment on OS-X and Windows). To change this, set the $PYTHON environment variable. For details, see the PyCall.jl and PyPlot.jl documentation.

If you want to use a standalone Jupyter/Python installation with Julia, we recommend installing Anaconda.

Jupyter alternative: Installing nteract

On local systems, you can use the nteract deskop application to run Jupyter notebooks, instead of using a Jupyter server. Like Jupyter, nteract should detect the Jupyter Julia kernel (see below) automatically.

Environment variables

You may want/need to set the following environment variables:

  • $PATH: Include the Julia bin-directory in your binary search path, see above. If you intend to use Jupyter, you will probably want to include the directory containing the jupyter binary to your PATH as well.

  • $JULIA_NUM_THREADS: Number of threads to use for Julia multi-threading

  • $JULIA_DEPOT_PATH and JULIA_PKG_DEVDIR: If you want Julia to install packages in another location than $HOME/.julia.

See the Julia manual for a description of other Julia-specific environment variables.

Installing the Jupyter Julia kernel

First install the IJulia Jupyter Julia kernel, Interact.JL and WebIO.jl in your default Julia project environment via

julia -e 'using Pkg; Pkg.add(["IJulia", "Interact", "WebIO"]); Pkg.build("IJulia")'

Also run

julia -e 'using WebIO; WebIO.install_jupyter_nbextension()'

to install a Jupyter extension that WebIO.jl (used by Interact.jl) requires to function.

To configure Julia to use multiple threads when run as a Jupyter kernel, use

julia -e 'using IJulia; IJulia.installkernel("Julia", "--project=@.", "--threads=auto")'

On Julia versions older than v1.6, you need to use

julia -e 'using IJulia; IJulia.installkernel("Julia", "--project=@.", env=Dict("JULIA_NUM_THREADS"=>"4"))'

instead.

Setting up this course

Download this course via Git and change into the "julia-course" directory:

git clone https://github.com/oschulz/julia-course.git
cd julia-course

Julia has a very powerful package management system that allows for using different versions of packages for different projects, layered package environments, etc. Run the shell command

julia --project=. -e 'using Pkg; Pkg.instantiate(); Pkg.precompile()'

to instantiate the Julia project environment defined by the files "Project.toml" and "Manifest.toml" in the "julia-course" directory.

Note that the "IJulia" package should always be installed in the default environment (see above) and not in individual project environments, to avoid version conflicts (since the Jupyter kernel will always try to load the same one).

Optional: To make this environment provided with this course your default Julia environment, typically located in "$HOME/user/.julia/environments/v1.6", simply copy the files "Project.toml" and "Manifest.toml" there, and then add IJulia (see above).

Using the Jupyter notebooks

First ensure that you have the "IJulia" package installed, which provides the Jupyter Julia kernel. Test by running (should not report an error)

julia -e 'using IJulia'

If you do not have a Jupyter installation on your $PATH, you may want to start Jupyter via Julia or (on a desktop system) use nteract.

If you do have a Jupyter installation on your $PATH (preferred), you can usually just start a Jupyter notebook server using

jupyter notebook

When using a Jupyter installation on your local system, your web browser will usually be started automatically and be pointed to the Jupyter notebook server instance. However, when using a software container or when starting Jupyter on a remote system using SSH port forwarding (and in some other cases), Jupyter will complain that it can't start a web browser. In these cases, run

jupyter notebook --no-browser

Jupyter will print the URL to point your web browser too. That URL should include an authorization token (unless you configured Jupyter for password-based access).

Depending on where and how you run Jupyter - especially if you run in a Docker container - you may need to specify a non-standard port number and/or IP address to bind to, or allow Jupyter to run in a root user account. In such cases, additional options will be required, e.g.:

jupyter notebook --no-browser --ip 0.0.0.0 --port 8888 --allow-root

About

Introductory Julia Course

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published