Support #923
Updated by Daniel Curtis almost 7 years ago
{{>toc}} This is a guide on installing a self-hosted Jupyter Notebook instance with Python 3.6 (along with Python 2.7) on FreeBSD 11-STABLE. h2. Prepare the Environment * Make sure the system is up to date: <pre> pkg update && pkg upgrade </pre> * Add jupyter user: <pre> pw add user -n jupyter -m -s /bin/sh -c "Jupyter Notebook" </pre> h3. Python 2.7 * Install the dependencies: <pre> pkg install python2 py27-{pip,pandas,numpy,matplotlib,setuptools,virtualenv} </pre> h3. Python 3.6 * Install the dependencies using pkgng: <pre> pkg install python3 py36-{pip,pandas,numpy,matplotlib,setuptools,virtualenv} </pre> h2. Install Jupyter Notebook * Install Jupyter Notebook: <pre> pip-3.6 install jupyter </pre> * Generate an initial config: <pre> su - jupyter -c "jupyter notebook --generate-config" </pre> * Edit the config: <pre> vi /home/jupyter/.jupyter/jupyter_notebook_config.py </pre> #* And modify the following parameters: <pre> c.NotebookApp.ip ='*' c.NotebookApp.open_browser = False c.NotebookApp.notebook_dir = '/tmp' c.NotebookApp.port = 8888 </pre> * Test run Jupyter Notebook: <pre> su - jupyter -c 'jupyter notebook' </pre> h3. Enable Python 2.7 Kernel * Install the ipykernel for version 2.7: <pre> pip-2.7 install ipykernel </pre> * Install the ipykernel 2.7 or the jupyter user: <pre> su - jupyter -c 'python2.7 -m ipykernel install --user' </pre> h3. init script * Create a folder for the pidfile: <pre> mkdir /var/run/jupyter chown jupyter /var/run/jupyter </pre> * Create an init script for jupyter notebook: <pre> vi /usr/local/etc/rc.d/jupyter </pre> #* And add the following: <pre> #!/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" </pre> * Make the script executable: <pre> chmod +x /usr/local/etc/rc.d/jupyter </pre> * Start and enable jupyter at boot: <pre> sysrc jupyter_enable=YES service jupyter start </pre> h2. Resources * http://www.mianchen.com/running-my-own-jupyter-notebook-server-in-a-freebsd-jail/ * https://github.com/jupyter/notebook * https://stackoverflow.com/questions/30492623/using-both-python-2-x-and-python-3-x-in-ipython-notebook