Support #923
Install Jupyter Notebook on FreeBSD
Description
- Table of contents
- Prepare the Environment
- Install Jupyter Notebook
- Resources
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
- And modify the following parameters:
- 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"
- And add the following:
- 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¶
Updated by Daniel Curtis almost 7 years ago
- Description updated (diff)
- Status changed from New to In Progress
Updated by Daniel Curtis almost 7 years ago
- Description updated (diff)
- % Done changed from 0 to 100
Updated by Daniel Curtis almost 5 years ago
- Description updated (diff)
- Target version changed from FreeBSD 11 to FreeBSD 12