title | parent | tags | categories | description | date | redirect_from | mrm | xredirect | slug | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Install JupyterLab in OCI |
tutorials |
|
|
This tutorial will guide you through setting up your environment to run JupyterLab on Oracle Cloud Infrastructure. |
2021-10-07 14:27 |
/collections/tutorials/install-jupyter-lab-on-oci/ |
WWMK211117P00079 |
install-jupyter-lab-on-oci |
{% slides %}
This tutorial will guide you through setting up your environment to run JupyterLab on Oracle Cloud Infrastructure. JupyterLab is the web-based user interface for Project Jupyter.
For additional information, see:
- Getting started with JupyterLab
- JupyterLab Documentation
- Signing Up for Oracle Cloud Infrastructure
- Getting started with OCI Cloud Shell
To successfully complete this tutorial, you'll need the following:
- An Oracle Cloud Infrastructure Free Tier account. [Start for Free]({{ site.urls.always_free }}).
- A MacOS, Linux, or Windows computer with
ssh
support installed. - OCI Cloud Shell (It provides a great platform for quickly working with Terraform as well as a host of other OCI interfaces and tools.)
- Virtual Machine 2.1 with Oracle Linux 7.9 (OEL7) deployed in Oracle Cloud Infrastructure (OCI).
- Oracle Linux 7.9 using pip3.6 by default.
- Python 3.6 or higher installed
- Access to root, either directly or via sudo.
By default in OCI, you are connected as theopc
user with sudo privilege.
Getting up and running with JupyterLab is pretty simple. We'll cover all the important steps in this tutorial:
- Setting up Python and installing Python components and libraries
- Installing JupyterLab
- Configuring JupyterLab
Lets start with setting up the Python Environment.
By default, OEL7 runs Python 3. The first step is to install pip
and virtualenv
.
-
Install
virtualenv
Virtualenv enables us to create isolated sandboxes for developing Python applications without running into module or library conflicts. It's very simple to install:
sudo pip3.6 install virtualenv
-
Next, we create a virtual environment called
myvirtualenv
virtualenv -p /usr/bin/python3 myvirtualenv
-
To activate the new environment:
source myvirtualenv/bin/activate
-
Now, to get a list of Python Libraries in our environment.
The following command will show which Python models we have installed at this point:
(myvirtualenv)$ pip3 list Package Version ---------- ------- pip 21.1.3 setuptools 57.1.0 wheel 0.36.2 WARNING: You are using pip version 21.1.3; however, version 21.2.1 is available. You should consider upgrading via the '/home/opc/myvirtualenv/bin/python -m pip install --upgrade pip' command. ```
-
To upgrade your PIP Environment for this virtual environment:
/home/opc/myvirtualenv/bin/python -m pip install --upgrade pip
-
Use
pip
to install JupyterLab:pip3 install jupyterlab
-
Install Python Libraries for Machine Learning or ETL Process:
pip install pandas pip install pandarallel pip install dask pip install seaborn pip install matplotlib pip install plotly pip install -lxml==4.6.3 pip install selenium pip install beautifulsoup4 pip install scikit-learn
-
Install other Python libraries for Kafka Access and WEB Server Access:
pip install kafka-python (v2.0.0) pip install Flask pip install gunicorn
-
Install extensions for JupyterLab environment:
pip install jupyter_contrib_nbextensions jupyter contrib nbextension install --user jupyter nbextension enable execute_time/ExecuteTime
-
Create a script to instantiate automatically and reboot jupyterlab with the
opc
user.vi /home/opc/launchjupyterlab.sh
-
Add the following content to
launchjupyterlab.sh
.
You must use thevirtualenv
you created, and you can launch JupyterLab on a specific port (e.g., 8001) and listen on your VM's public IP.#!/bin/bash # Activate myvirtualenv Environment source myvirtualenv/bin/activate cd /home/opc if [ "$1" = "start" ]; then nohup jupyter-lab --ip=0.0.0.0 --port=8001 > ./nohup.log 2>&1 & echo $! > /home/opc/jupyter.pid else kill $(cat /home/opc/jupyter.pid) fi
-
Now, we'll need to make the script executable so it can be run from the jupyterlab service:
chmod 777 /home/opc/launchjupyterlab.sh
-
Connect to the
root
user:sudo -i
-
Create a script to start and stop the jupyterlab service:
vi /etc/systemd/system/jupyterlab.service
-
Add the following to
jupyterlab.service
:[Unit] Description=Service to start jupyterlab for opc Documentation= [Service] User=opc Group=opc Type=forking WorkingDirectory=/home/opc ExecStart=/home/opc/launchjupyterlab.sh start ExecStop=/home/opc/launchjupyterlab.sh stop [Install] WantedBy=multi-user.target
-
Test the JupyterLab Service:
systemctl start jupyterlab systemctl status jupyterlab systemctl enable jupyterlab
-
Reboot your machine to check if the
jupyterlab
script is enabled by default on the port we defined (8001). -
Open port 8001 to your virtual machine VM 2.1 so you can access JupyterLab using your Public IP:
firewall-cmd --permanent --zone=public --list-ports firewall-cmd --get-active-zones firewall-cmd --permanent --zone=public --add-port=8001/tcp firewall-cmd --reload
-
Connect to
http://xxx.xxx.xxx.xxx:8001/
(replacingxxx
with your public IP) in your browser.NOTE: If you're running directly on a virtual machine and have a browser installed, it should take you directly into the Jupyter environment. {:.notice}
You should now see the Python Web environment "JupyterLab".
To explore more information about development with Oracle products:
{% endslides %}