Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a julia function from jupyter notebook (import Julia jupyter notebook)

With Python I can reuse another Jupyter notebook by importing it directly to a new one as a module (here in Anaconda) or using nbpackage.

Can this be done with Julia Jupyter notebooks? How to import functions from one notebook into another?

like image 261
sophros Avatar asked Apr 08 '20 17:04

sophros


People also ask

Can we run Julia in Jupyter notebook?

After installing the necessary packages for your purposes, you can experience the high-performance Julia language in Jupyter notebook.

How do I open Jupyter notebook from Julia terminal?

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.


1 Answers

The solution is to use NBInclude.jl package:

using NBInclude
@nbinclude("my_other_jupyter_notebook.ipynb")

This construct is analogous to having the code from notebook stored in a some.jl file and included as typical:

include("some.jl")

Please note that there are different scoping considerations at play depending on the version of Julia you use (1.0 or 0.6). Please refer to the documentation.

Installation via:

using Pkg
Pkg.add("NBInclude")

or REPL / ] (package management mode):

add NBInclude
like image 173
sophros Avatar answered Oct 07 '22 18:10

sophros