In this lecture we will cover how to get up and running with Julia.
If you have access to a web-based Jupyter and Julia setup, it is typically the most straightforward way to get started.
A Note on Jupyter¶
Like Python and R, and unlike products such as Matlab and Stata, there is a looser connection between Julia as a programming language and Julia as a specific development environment.
While you will eventually use other editors, there are some advantages to starting with the Jupyter environment while learning Julia.
- The ability to mix formatted text (including mathematical expressions) and code in a single document.
- Nicely formatted output including tables, figures, animation, video, etc.
- Conversion tools to generate PDF slides, static HTML, etc.
- Online Jupyter may be available, and requires no installation.
We’ll discuss the workflow on these features in the next lecture.
Desktop Installation of Julia and Jupyter¶
If you want to install these tools locally on your machine
Download and install Julia, from download page , accepting all default options.
- We do not recommend JuliaPro.
Open Julia, by either
- Navigating to Julia through your menus or desktop icons (Windows, Mac), or
- Opening a terminal and typing
julia(Linux; to set this up on Mac, see end of section)
You should now be looking at something like this
This is called the JULIA REPL (Read-Evaluate-Print-Loop), which we discuss more later.
- In the Julia REPL, hit
]to enter package mode and then enter.
add IJulia InstantiateFromURL
This adds packages for
IJuliakernel which links Julia to Jupyter (i.e., allows your browser to run Julia code, manage Julia packages, etc.).
InstantiateFromURLwhich is a tool written by the QE team to manage package dependencies for the lectures.
Note: To set up the Julia terminal command on Mac, open a terminal and run
go to a terminal and run ``sudo ln -s <where_julia_app_is>/Contents/Resources/julia/bin/julia /usr/local/bin/julia.
The full command might look like
sudo ln -s /Applications/Julia-1.2.app/Contents/Resources/julia/bin/julia /usr/local/bin/julia, if you placed the app in your
If you have previously installed Jupyter (e.g., installing Anaconda Python by downloading the binary https://www.anaconda.com/download/)
add IJulia installs everything you need into your existing environment.
Otherwise - or in addition - you can install it directly from the Julia REPL
using IJulia; jupyterlab()
Choose the default,
y if asked to install Jupyter and then JupyterLab via Conda.
After the installation, a JupyterLab tab should open in your browser.
(Optional) To enable launching JupyterLab from a terminal, use add Julia’s Jupyter to your path.
GitHub Desktop Approach¶
After installing the Git Desktop application, click this link on your desktop computer to automatically install the notebooks.
It should open a window in the GitHub desktop app like this
Choose a path you like and clone the repo.
Note: the workflow will be easiest if you clone the repo to the default location relative to the home folder for your user.
From a Julia REPL, start JupyterLab by executing
using IJulia; jupyterlab()
Git Command Line Approach¶
If you do not wish to install the GitHub Desktop, you can get the notebooks using the Git command-line tool.
Open a new terminal session and run
git clone https://github.com/quantecon/quantecon-notebooks-julia
This will download the repository with the notebooks in the working directory.
cd to that location in your Mac, Linux, or Windows PowerShell terminal
Then, either using the
using IJulia; jupyterlab() or execute
jupyter lab within your shell.
And open the Interacting With Julia lecture (the file
julia_environment.ipynb in the list of notebooks in JupyterLab) to continue.
Using Julia with JupyterHub¶
If you have access to a web-based solution for Jupyter, then that is typically a straightforward option
- Students: ask your department if these resources are available.
- Universities and workgroups: email email@example.com for help on setting up a shared JupyterHub instance with precompiled packages ready for these lecture notes.
- JuliaBox tightly controls allowed packages, and does not currently support the QuantEcon lectures.
Your first step is to get a copy of the notebooks in your JupyterHub environment.
While you can individually download the notebooks from the website, the easiest way to access the notebooks is usually to clone the repository with Git into your JupyterHub environment.
JupyterHub installations have different methods for cloning repositories, with which you can use the url for the notebooks repository:
After you have some of the notebooks available, as in above, these lectures depend on functionality (like packages for plotting, benchmarking, and statistics) that are not installed with every Jupyter installation on the web.
If your online Jupyter does not come with QuantEcon packages pre-installed, you can install the
InstantiateFromURL package, which is a tool written by the QE team to manage package dependencies for the lectures.
To add this package, in an online Jupyter notebook run (typically with
] add InstantiateFromURL
If your online Jupyter environment does not have the packages pre-installed, it may take 15-20 minutes for your first QuantEcon notebook to run.
After this step, open the downloaded Interacting with Julia notebook to begin writing code.
If the QuantEcon notebooks do not work after this installation step, you may need to speak to the JupyterHub administrator.