Project

General

Profile

Support #923

Install Jupyter Notebook on FreeBSD

Added by Daniel Curtis about 6 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Development
Target version:
Start date:
03/04/2018
Due date:
% Done:

100%

Estimated time:
1.00 h
Spent time:

Description

This is a guide on installing a self-hosted Jupyter Notebook instance with Python 3.7 (along with Python 2.7) on FreeBSD 12-RELEASE.

Prepare the Environment

  • Make sure the system is up to date:
    pkg update && pkg upgrade
    
  • Add jupyter user:
    pw add user -n jupyter -m -s /bin/sh -c "Jupyter Notebook" 
    

Python 2.7

  • Install the dependencies:
    pkg install python2 py27-{pip,pandas,numpy,matplotlib,setuptools,virtualenv}
    

Python 3.7

  • Install the dependencies using pkgng:
    pkg install python3 py37-{pip,pandas,numpy,matplotlib,setuptools,virtualenv}
    

Install Jupyter Notebook

  • Install Jupyter Notebook:
    pip-3.7 install jupyter
    
  • Generate an initial config:
    su - jupyter -c "jupyter notebook --generate-config" 
    
  • Edit the config:
    vi /home/jupyter/.jupyter/jupyter_notebook_config.py
    
    • And modify the following parameters:
      c.NotebookApp.ip ='*'
      c.NotebookApp.open_browser = False
      c.NotebookApp.notebook_dir  = '/tmp'
      c.NotebookApp.port = 8888
      
  • Test run Jupyter Notebook:
    su - jupyter -c 'jupyter notebook'
    

Enable 2.7 Kernel

  • Install the ipykernel for version 2.7:
    pip-2.7 install ipykernel
    
  • Install the ipykernel 2.7 or the jupyter user:
    su - jupyter -c 'python2.7 -m ipykernel install --user'
    

Enable Java

  • Install prerequisites:
    pkg install openjdk11 wget
    
  • Fetch ijava:
    cd ~ && mkdir ijava && cd ijava
    wget --no-check-certificate http://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3.0.zip
    unzip ijava-1.3.0.zip
    
  • Install ijava:
    python3 install.py --sys-prefix
    

init script

  • Create a folder for the pidfile:
    mkdir /var/run/jupyter
    chown jupyter /var/run/jupyter
    
  • Create an init script for jupyter notebook:
    vi /usr/local/etc/rc.d/jupyter
    
    • And add the following:
      #!/bin/sh
      #
      # PROVIDE: jupyter
      # REQUIRE: LOGIN
      #
      # Add the following lines to /etc/rc.conf to enable jupyter notebook server
      #
      #
      # jupyter_enable (bool): Set to "NO" by default,
      #                         Set it to "YES" to enable jupyter notebook server
      
      . /etc/rc.subr
      
      name=jupyter
      command=/usr/local/bin/jupyter
      rcvar=jupyter_enable
      
      load_rc_config $name
      
      jupyter_enable="${jupyter_enable-"NO"}" 
      jupyter_user="${jupyter_user-"jupyter"}" 
      jupyter_pidfile="${jupyter_pidfile:-"/var/run/jupyter/jupyter.pid"}"  
      
      # /etc/rc.subr use $pidfile (not ${name}_pidfile)
      pidfile="${jupyter_pidfile}" 
      
      start_cmd="su - ${jupyter_user} -c '${command} notebook' &" 
      stop_cmd="${name}_stop" 
      status_cmd="${name}_status" 
      getval_cmd="${name}_getval" 
      
      jupyter_stop()
      {
          jupyter_pid=$(pgrep -f "jupyter-notebook")
      
          echo "Stopping ${name}." 
          kill -s TERM "$(cat "${jupyter_pidfile}")" 
      
          echo "Stopping ${name}." 
          kill -s TERM "${jupyter_pid}" 
      
          rm ${jupyter_pidfile}
      }
      
      jupyter_status()
      {
          # Try its best to find the service's status
          if [ -f "${jupyter_pidfile}" ]
          then
              jupyter_pid="$(cat "${jupyter_pidfile}")" 
          fi
      
          if [ -z "${jupyter_pid}" ]
          then
          jupyter_pid=$(pgrep -f "jupyter-notebook")
          [ -n "${jupyter_pid}" ] && echo "${jupyter_pid}" > "${jupyter_pidfile}" 
          fi
      
          if [ -n "${jupyter_pid}" ]
          then
              echo "${name} running with pid: $jupyter_pid" 
          else
              echo "${name} not running? (pid not found)" 
          fi
      }
      
      command_args=" >/dev/null 2>&1 &" 
      
      load_rc_config $name
      run_rc_command "$1" 
      
  • Make the script executable:
    chmod +x /usr/local/etc/rc.d/jupyter
    
  • Start and enable jupyter at boot:
    sysrc jupyter_enable=YES
    service jupyter start
    

Resources

#1

Updated by Daniel Curtis about 6 years ago

  • Description updated (diff)
  • Status changed from New to In Progress
#2

Updated by Daniel Curtis about 6 years ago

  • Description updated (diff)
  • % Done changed from 0 to 100
#3

Updated by Daniel Curtis about 6 years ago

  • Description updated (diff)
#4

Updated by Daniel Curtis about 6 years ago

  • Description updated (diff)
#5

Updated by Daniel Curtis about 6 years ago

  • Status changed from In Progress to Resolved
#6

Updated by Daniel Curtis about 6 years ago

  • Status changed from Resolved to Closed
#7

Updated by Daniel Curtis about 4 years ago

  • Description updated (diff)
  • Target version changed from FreeBSD 11 to FreeBSD 12
#8

Updated by Daniel Curtis about 4 years ago

  • Description updated (diff)

Also available in: Atom PDF