scrapbook
  • "Unorganized" Notes
  • The Best Public Datasets for Machine Learning and Data Science
  • Practice Coding
  • plaid-API project
  • Biotech
    • Machine Learning vs. Deep Learning
  • Machine Learning for Computer Graphics
  • Books (on GitHub)
  • Ideas/Thoughts
  • Ziva for feature animation: Stylized simulation and machine learning-ready workflows
  • Tools
  • 🪶math
    • Papers
    • Math for ML (coursera)
      • Linear Algebra
        • Wk1
        • Wk2
        • Wk3
        • Wk4
        • Wk5
      • Multivariate Calculus
    • Improving your Algorithms & Data Structure Skills
    • Algorithms
    • Algorithms (MIT)
      • Lecture 1: Algorithmic Thinking, Peak Finding
    • Algorithms (khan academy)
      • Binary Search
      • Asymptotic notation
      • Sorting
      • Insertion sort
      • Recursion
      • Solve Hanoi recursively
      • Merge Sort
      • Representing graphs
      • The breadth-first search algorithm
      • Breadth First Search in JavaScript
      • Breadth-first vs Depth-first Tree Traversal in Javascript
    • Algorithms (udacity)
      • Social Network
    • Udacity
      • Linear Algebra Refresher /w Python
    • math-notes
      • functions
      • differential calculus
      • derivative
      • extras
      • Exponentials & logarithms
      • Trigonometry
    • Probability (MIT)
      • Unit 1
        • Probability Models and Axioms
        • Mathematical background: Sets; sequences, limits, and series; (un)countable sets.
    • Statistics and probability (khan academy)
      • Analyzing categorical data
      • Describing and comparing distributions
      • Outliers Definition
      • Mean Absolute Deviation (MAD)
      • Modeling data distribution
      • Exploring bivariate numerical data
      • Study Design
      • Probability
      • Counting, permutations, and combinations
      • Binomial variables
        • Binomial Distribution
        • Binomial mean and standard deviation formulas
        • Geometric random variable
      • Central Limit Theorem
      • Significance Tests (hypothesis testing)
    • Statistics (hackerrank)
      • Mean, Medium, Mode
      • Weighted Mean
      • Quartiles
      • Standard Deviation
      • Basic Probability
      • Conditional Probability
      • Permutations & Combinations
      • Binomial Distribution
      • Negative Binomial
      • Poisson Distribution
      • Normal Distribution
      • Central Limit Theorem
      • Important Concepts in Bayesian Statistics
  • 📽️PRODUCT
    • Product Strategy
    • Product Design
    • Product Development
    • Product Launch
  • 👨‍💻coding
    • of any interest
    • Maya API
      • Python API
    • Python
      • Understanding Class Inheritance in Python 3
      • 100+ Python challenging programming exercises
      • coding
      • Iterables vs. Iterators vs. Generators
      • Generator Expression
      • Stacks (LIFO) / Queues (FIFO)
      • What does -1 mean in numpy reshape?
      • Fold Left and Right in Python
      • Flatten a nested list of lists
      • Flatten a nested dictionary
      • Traverse A Tree
      • How to Implement Breadth-First Search
      • Breadth First Search
        • Level Order Tree Traversal
        • Breadth First Search or BFS for a Graph
        • BFS for Disconnected Graph
      • Trees and Tree Algorithms
      • Graph and its representations
      • Graph Data Structure Interview Questions
      • Graphs in Python
      • GitHub Repo's
    • Python in CG Production
    • GLSL/HLSL Shading programming
    • Deep Learning Specialization
      • Neural Networks and Deep Learning
      • Untitled
      • Untitled
      • Untitled
    • TensorFlow for AI, ML, and DL
      • Google ML Crash Course
      • TensorFlow C++ API
      • TensorFlow - coursera
      • Notes
      • An Introduction to different Types of Convolutions in Deep Learning
      • One by One [ 1 x 1 ] Convolution - counter-intuitively useful
      • SqueezeNet
      • Deep Compression
      • An Overview of ResNet and its Variants
      • Introducing capsule networks
      • What is a CapsNet or Capsule Network?
      • Xception
      • TensorFlow Eager
    • GitHub
      • Project README
    • Agile - User Stories
    • The Open-Source Data Science Masters
    • Coding Challenge Websites
    • Coding Interview
      • leetcode python
      • Data Structures
        • Arrays
        • Linked List
        • Hash Tables
        • Trees: Basic
        • Heaps, Stacks, Queues
        • Graphs
          • Shortest Path
      • Sorting & Searching
        • Depth-First Search & Breadth-First Search
        • Backtracking
        • Sorting
      • Dynamic Programming
        • Dynamic Programming: Basic
        • Dynamic Programming: Advanced
    • spaCy
    • Pandas
    • Python Packages
    • Julia
      • jupyter
    • macos
    • CPP
      • Debugging
      • Overview of memory management problems
      • What are lvalues and rvalues?
      • The Rule of Five
      • Concurrency
      • Avoiding Data Races
      • Mutex
      • The Monitor Object Pattern
      • Lambdas
      • Maya C++ API Programming Tips
      • How can I read and parse CSV files in C++?
      • Cpp NumPy
    • Advanced Machine Learning
      • Wk 1
      • Untitled
      • Untitled
      • Untitled
      • Untitled
  • data science
    • Resources
    • Tensorflow C++
    • Computerphile
      • Big Data
    • Google ML Crash Course
    • Kaggle
      • Data Versioning
      • The Basics of Rest APIs
      • How to Make an API
      • How to deploying your API
    • Jupiter Notebook Tips & Tricks
      • Jupyter
    • Image Datasets Notes
    • DS Cheatsheets
      • Websites & Blogs
      • Q&A
      • Strata
      • Data Visualisation
      • Matplotlib etc
      • Keras
      • Spark
      • Probability
      • Machine Learning
        • Fast Computation of AUC-ROC score
    • Data Visualisation
    • fast.ai
      • deep learning
      • How to work with Jupyter Notebook on a remote machine (Linux)
      • Up and Running With Fast.ai and Docker
      • AWS
    • Data Scientist
    • ML for Beginners (Video)
    • ML Mastery
      • Machine Learning Algorithms
      • Deep Learning With Python
    • Linear algebra cheat sheet for deep learning
    • DL_ML_Resources
    • Awesome Machine Learning
    • web scraping
    • SQL Style Guide
    • SQL - Tips & Tricks
  • 💡Ideas & Thoughts
    • Outdoors
    • Blog
      • markdown
      • How to survive your first day as an On-set VFX Supervisor
    • Book Recommendations by Demi Lee
  • career
    • Skills
    • learn.co
      • SQL
      • Distribution
      • Hypothesis Testing Glossary
      • Hypothesis Tests
      • Hypothesis & AB Testing
      • Combinatorics Continued and Maximum Likelihood Estimation
      • Bayesian Classification
      • Resampling and Monte Carlo Simulation
      • Extensions To Linear Models
      • Time Series
      • Distance Metrics
      • Graph Theory
      • Logistic Regression
      • MLE (Maximum Likelihood Estimation)
      • Gradient Descent
      • Decision Trees
      • Ensemble Methods
      • Spark
      • Machine Learning
      • Deep Learning
        • Backpropagation - math notation
        • PRACTICE DATASETS
        • Big Data
      • Deep Learning Resources
      • DL Datasets
      • DL Tutorials
      • Keras
      • Word2Vec
        • Word2Vec Tutorial Part 1 - The Skip-Gram Model
        • Word2Vec Tutorial Part 2 - Negative Sampling
        • An Intuitive Explanation of Convolutional Neural Networks
      • Mod 4 Project
        • Presentation
      • Mod 5 Project
      • Capstone Project Notes
        • Streaming large training and test files into Tensorflow's DNNClassifier
    • Carrier Prep
      • The Job Search
        • Building a Strong Job Search Foundation
        • Key Traits of Successful Job Seekers
        • Your Job Search Mindset
        • Confidence
        • Job Search Action Plan
        • CSC Weekly Activity
        • Managing Your Job Search
      • Your Online Presence
        • GitHub
      • Building Your Resume
        • Writing Your Resume Summary
        • Technical Experience
      • Effective Networking
        • 30 Second Elevator Pitch
        • Leveraging Your Network
        • Building an Online Network
        • Linkedin For Research And Networking
        • Building An In-Person Network
        • Opening The Line Of Communication
      • Applying to Jobs
        • Applying To Jobs Online
        • Cover Letters
      • Interviewing
        • Networking Coffees vs Formal Interviews
        • The Coffee Meeting/ Informational Interview
        • Communicating With Recruiters And HR Professional
        • Research Before an Interview
        • Preparing Questions for Interviews
        • Phone And Video/Virtual Interviews
        • Cultural/HR Interview Questions
        • The Salary Question
        • Talking About Apps/Projects You Built
        • Sending Thank You's After an Interview
      • Technical Interviewing
        • Technical Interviewing Formats
        • Code Challenge Best Practices
        • Technical Interviewing Resources
      • Communication
        • Following Up
        • When You Haven't Heard From an Employer
      • Job Offers
        • Approaching Salary Negotiations
      • Staying Current in the Tech Industry
      • Module 6 Post Work
      • Interview Prep
  • projects
    • Text Classification
    • TERRA-REF
    • saildrone
  • Computer Graphics
  • AI/ML
  • 3deeplearning
    • Fast and Deep Deformation Approximations
    • Compress and Denoise MoCap with Autoencoders
    • ‘Fast and Deep Deformation Approximations’ Implementation
    • Running a NeuralNet live in Maya in a Python DG Node
    • Implement a Substance like Normal Map Generator with a Convolutional Network
    • Deploying Neural Nets to the Maya C++ API
  • Tools/Plugins
  • AR/VR
  • Game Engine
  • Rigging
    • Deformer Ideas
    • Research
    • brave rabbit
    • Useful Rigging Links
  • Maya
    • Optimizing Node Graph for Parallel Evaluation
  • Houdini
    • Stuff
    • Popular Built-in VEX Attributes (Global Variables)
Powered by GitBook
On this page
  • IJulia
  • Installation
  • IJulia features
  • Low-level Information
  • Debugging IJulia problems
  1. coding
  2. Julia

jupyter

PreviousJuliaNextmacos

Last updated 6 years ago

IJulia

IJulia is a backend combined with the interactive environment (also used by ). This combination allows you to interact with the Julia language using Jupyter/IPython's powerful , which combines code, formatted text, math, and multimedia in a single document. It also works with , a Jupyter-based integrated development environment for notebooks and code.

(IJulia notebooks can also be re-used in other Julia code via the package.)

Installation

First, 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 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 setting ENV["JUPYTER"] to the path of the jupyter program before Pkg.add, or before running Pkg.build("IJulia"); your preference is remembered on subsequent updates.

Running the IJulia Notebook

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 julia> prompt:

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 package to install a minimal Python+Jupyter distribution (via ) that is private to Julia (not in your PATH). On Linux, it defaults to looking for jupyter in your PATH first, 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 jupyter.)

You can use 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 notebook(dir="/some/path").

Alternatively, you can run

jupyter notebook

Running the JupyterLab

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 julia> prompt:

using IJulia
jupyterlab()

Like notebook(), above, this will install JupyterLab via Conda if it is not installed already. jupyterlab() also supports detached and dir keyword options similar to notebook().

Updating Julia and IJulia

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:

Pkg.update()

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

Pkg.build("IJulia")

at the Julia command line (important: not in IJulia).

Installing additional Julia kernels

You can also install additional Julia kernels, for example, to pass alternative command-line arguments to the juliaexecutable, by using the IJulia.installkernel function. See the help for this function (? 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"))

The env keyword should be a Dict mapping environment variables to values.

Troubleshooting:

  • If you ran into a problem with the above steps, after fixing the problem you can type Pkg.build() to try to rerun the install scripts.

  • If you tried it a while ago, try running 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 .julia directory in your home directory (on Windows, it is called Users\USERNAME\.julia in your home directory) via rm(Pkg.dir(),recursive=true) in Julia and re-adding the packages.

  • Internet Explorer 8 (the default in Windows 7) or 9 don't work with the notebook; use Firefox (6 or later) or Chrome (13 or later). Internet Explorer 10 in Windows 8 works (albeit with a few rendering glitches), but Chrome or Firefox is better.

  • Try running jupyter --version and make sure that it prints 3.0.0 or larger; earlier versions of IPython are no longer supported by IJulia.

  • You can try setting ENV["JUPYTER"]=""; Pkg.build("IJulia") to force IJulia to go back to its own Conda-based Jupyter version (if you previously tried a different jupyter).

IJulia features

There are various features of IJulia that allow you to interact with a running IJulia kernel.

Detecting that code is running under IJulia

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.

Customizing your IJulia environment

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., ~/.julia/config/startup_ijulia.jl.

Julia and IPython Magics

One difference from IPython is that the IJulia kernel does not use "magics", which are special commands prefixed with % or%% 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 more powerful.

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 is IJulia.load("filename").

Prompting for user input

When you are running in a notebook, ordinary I/O functions on stdin do not function. However, you can prompt for the user to enter a string in one of two ways:

  • readline() and readline(stdin) both open a stdin> prompt widget where the user can enter a string, which is returned by readline.

  • IJulia.readprompt(prompt) displays the prompt string prompt and returns a string entered by the user.IJulia.readprompt(prompt, password=true) does the same thing but hides the text the user types.

Clearing output

IJulia.clear_output(wait=false)

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 calls to IJulia.clear_output(true) followed by calls to display(...) to display a new animation frame.

Default display size

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 LINES and COLUMNS environment variables, respectively, which can also be changed within IJulia via ENV (e.g. ENV["LINES"] = 60). (Like in the REPL, you can also display non-truncated data structures via print(x).)

Preventing truncation of output

The new default behavior of IJulia is to truncate stdout (via show or println) 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)

Setting the current module

The module that code in an input cell is evaluated in can be set using Main.IJulia.set_current_module(::Module). It defaults to Main.

Opting out of soft scope

To opt out of this behavior, making notebooks behave similarly to global code in Julia .jl files, you can set IJulia.SOFTSCOPE[] = false at runtime, or include the environment variable IJULIA_SOFTSCOPE=no environment of the IJulia kernel when it is launched.

Low-level Information

Using older IPython versions

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")

Manual installation of IPython

First, you will need to install a few prerequisites:

  • 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:

Pkg.add("IJulia")

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 Pkg.update(), then retry it, or possibly run Pkg.build("IJulia") to force a rebuild.

Other IPython interfaces

Debugging IJulia problems

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:

ENV["IJULIA_DEBUG"]=true
Pkg.build("IJulia")

Restart the notebook and look for the error message when IJulia dies. (This changes IJulia to default to verbose = truemode, and sets capture_stderr = false, hopefully sending a bunch of debugging to the terminal where you launched jupyter).

When you are done, set ENV["IJULIA_DEBUG"]=false and re-run Pkg.build("IJulia") to turn off the debugging output.

from the command line (the program in MacOS or the in Windows). Note that if you installed jupyter via automated Miniconda installer in Pkg.add, above, then jupyter may not be in your PATH; type import Conda; Conda.SCRIPTDIR in Julia to find out where Conda installed jupyter.

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 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 package.

You can also install kernels to run Julia with different environment variables, for example to set for use with Julia :

On MacOS, you currently need MacOS 10.7 or later; (unless you compile Julia yourself, from source code).

If the notebook opens up, but doesn't respond (the input label is In[*] indefinitely), try creating a new Python notebook (not Julia) from the New button in the Jupyter dashboard, to see if 1+1 works in Python. If it is the same problem, then probably you have a 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 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.)

Analogous to the function in IPython, IJulia provides a function:

By default, IJulia evaluates user code using "soft" global scope, via the : 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.

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 . On Mac and Windows systems, it is currently easiest to use the installer.

To use the interface, which runs in your web browser and provides a rich multimedia environment, you will need to install the , , , and (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 installer, pip install jsonschema jinja2 tornado pyzmq should normally be sufficient.) These should have been automatically installed if you installed IPython itself .

To use the interface, you will need to install or .

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 julia-0.7 or ipython console --kernel julia-0.7, respectively. (Replace 0.7 with whatever major Julia version you are using.)

👨‍💻
Julia-language
Jupyter
IPython
graphical notebook
JupyterLab
NBInclude
download Julia
kernel specification
Conda.jl
Miniconda
Terminal
Command Prompt
the Jupyter notebook documentation
NBInclude
JULIA_NUM_THREADS
multithreading
MacOS 10.6 doesn't work
firewall running
Sophos
IPython.display.clear_output()
SoftGlobalScope.jl package
install IPython manually
Anaconda Python
IPython notebook
jsonschema
Jinja2
Tornado
pyzmq
pip
via easy_install or pip
IPython qtconsole
PyQt4
PySide
qtconsole