Download PDF

We are working to support a site-wide PDF but it is not yet available. You can download PDFs for individual lectures through the download badge on each lecture page.

How to read this lecture...

Code should execute sequentially if run in a Jupyter notebook

  • See the set up page to install Jupyter, Julia (1.0+) and all necessary libraries
  • Please direct feedback to contact@quantecon.org or the discourse forum
  • For some notebooks, enable content with "Trust" on the command tab of Jupyter lab
  • If using QuantEcon lectures for the first time on a computer, execute ] add InstantiateFromURL inside of a notebook or the REPL

Setting up Your Julia Environment

Overview

In this lecture we will cover how to get up and running with Julia

There are a few different options for using Julia, including a local desktop installation and Jupyter hosted on the web

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

  • Install Anaconda Python by downloading the binary https://www.anaconda.com/download/

    • Make sure you click yes to “add Anaconda to my PATH”
  • Download and install Julia, from download page , accepting all default options

    • We do not recommend JuliaPro due to its limited number of available packages

  • Open Julia, by either

    1. Navigating to Julia through your menus or desktop icons (Windows, Mac), or
    2. Opening a terminal and typing julia (Linux)

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

  • The IJulia kernel which links Julia to Jupyter (i.e., allows your browser to run Julia code, manage Julia packages, etc.)
  • The InstantiateFromURL which is a tool written by the QE team to manage package dependencies for the lectures

Installing QuantEcon Packages

The next step in the installation process is to download and install all of the packages used by the QuantEcon lecture notes

  • Next, in the main REPL (that is, hit backspace from the blue package mode) run
using InstantiateFromURL

This will load the functions defined in the InstantiateFromURL package

  • Next, run the following (which may take 15-20 minutes depending on your internet connection and computer)
activate_github("QuantEcon/QuantEconLectureAllPackages", tag = "v0.9.6", add_default_environment = true)

This function will:

  1. Download two files, Project.toml and Manifest.toml, containing a list of the latest versions of the packages used in the the lecture notes
  2. Install those packages to your machine
  3. Add them to default Julia environment, so you can access the packages outside of QuantEcon lectures

Note: The number associated with the tag in the activate_github call is a snapshot of package versions used by the QuantEcon lectures at a particular point in time

We will cover “environments” more in depth later

Starting Jupyter

Next, let’s install the QuantEcon lecture notes to our machine and run them (for more details on the tools we’ll use, see our lecture on version control)

  1. Install git
  2. (Optional, but strongly recommended) Install the GitHub Desktop

GitHub Desktop Approach

Note: This workflow requires Git LFS (Large File Storage)

If you have not previously used Git LFS, choose to “Initialize Git LFS” at the dialog which appears while following these instructions

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

At this point, you should see the Git LFS dialog:

Hit accept

At the top, under the “Repository” dropdown, click “Open in Terminal” (Mac, Linux) or “Open in Command Prompt” (Windows)

Note: On Windows, you may need to click the “open without git” button that comes up

In the resulting terminal session, run

jupyter lab

You can open the Interacting with Julia notebook to explore this interface and start writing code

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

First, run the following to install Git LFS (Linux/OSX)

curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
git lfs install

As output from the last command, you should see Git LFS initialized.

Open a new terminal session and run

git clone https://github.com/quantecon/quantecon-notebooks-jl

This will download the repository with the notebooks in the working directory

Then, cd to that location in your Mac, Linux, or Windows PowerShell terminal

cd quantecon-notebooks-jl

Then, run

jupyter lab

And open the Interacting With Julia lecture (the file julia_environment.ipynb in the list of notebooks in JupyterLab) to continue

Using Julia on the Web

If you have access to an online Julia installation, it is the easiest way to get started

Eventually, you will want to do a local installation in order to use other tools and editors such as Atom/Juno, but don’t let the environment get in the way of learning the language

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 contact@quantecon.org 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

Obtaining Notebooks

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: https://github.com/QuantEcon/quantecon-notebooks-jl

Installing Packages

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 <Shift-Enter>)

In [1]:
] 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