Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install just one package globally on Julia

I have a fresh Julia instalation on a machine that I want to use as a number-crunching server for various persons on a lab. There seems to be this nice package called jupyterhub wich makes the Jupyter Notebook interface avaible to various clients simultaneusly. A web page which I am unable to find again began suggesting something like "first install IJulia globally, then install JupyterHub..."

I cannot seem to find a nice way to install ONE package globally.

like image 985
wpkzz Avatar asked Sep 01 '15 18:09

wpkzz


1 Answers

Update

In Julia-v0.7+, we need to use JULIA_DEPOT_PATH instead of JULIA_PKGDIR and the LOAD_PATH looks something like this:

julia> LOAD_PATH
3-element Array{Any,1}:
 Base.CurrentEnv()                                                                                                                     
 Any[Base.NamedEnv("v0.7.0"), Base.NamedEnv("v0.7"), Base.NamedEnv("v0"), Base.NamedEnv("default"), Base.NamedEnv("v0.7", create=true)]
 "/Users/gnimuc/Codes/julia/usr/share/julia/stdlib/v0.7" 

Old Post

"first install IJulia globally, then install JupyterHub..."

I don't know whether this is true or not, by following these steps below, you can install IJulia after you installed Jupyterhub.

Install packages system-wide/globally for every user

this question has already been answered here by Stefan Karpinski. so what we need is just use this method to install the IJulia.jl package.

There's a Julia variable called LOAD_PATH that is arranged to point at two system directories under your julia installation. E.g.:

julia> LOAD_PATH
2-element Array{Union(ASCIIString,UTF8String),1}:
 "/opt/julia-0.3.3/usr/local/share/julia/site/v0.3"
 "/opt/julia-0.3.3/usr/share/julia/site/v0.3"

If you install packages under either of those directories, then everyone using that Julia will see them. One way to do this is to run julia as a user who can write to those directories after doing export JULIA_PKGDIR=/opt/julia-0.3.3/usr/share/julia/site in the shell. That way Julia will use that as it's package directory and normal package commands will allow you to install packages for everyone....

Make IJulia working with Jupyterhub

in order to make IJulia and Jupyterhub working with each other for all the users, you should copy the folder your/user/.local/share/jupyter/kernels/julia/ to /usr/local/share/jupyter/kernels/. I write down some of the steps that I used in my test Dockerfile. the code is ugly, but it works.

Steps: (after you successfully installed Jupyterhub)

note that, you should do the following steps as root and I assume that your julia was globally installed at /opt/julia_0.4.0/.

  1. make our global package directory and set up JULIA_PKGDIR:

    mkdir /opt/global-packages
    echo 'push!(LOAD_PATH, "/opt/global-packages/.julia/v0.4/")' >> /opt/julia_0.4.0/etc/julia/juliarc.jl
    export JULIA_PKGDIR=/opt/global-packages/.julia/
    
  2. install "IJulia" using package manager:

    julia -e 'Pkg.init()'
    julia -e 'Pkg.add("IJulia")'
    
  3. copy kernelspecs to /usr/local/share/jupyter/kernels/ which can be used by any new user added by Jupyterhub:

    jupyter kernelspec list
    cd /usr/local/share/ && mkdir -p jupyter/kernels/
    cp -r /home/your-user-name/.local/share/jupyter/kernels/julia-0.4-your-julia-version /usr/local/share/jupyter/kernels/
    
like image 182
Gnimuc Avatar answered Oct 08 '22 08:10

Gnimuc