Skip to main content

Setting up Jupyter Lab integrated with Python, Julia, R on Windows Subsystem for Linux (Ubuntu)

Every guy gotta favorite OS. But, due to some constraints, all can't use that all the time. Being a Linux user, I had to shift to Windows 10 because of the barrier by MS Office and Dual booting often doesn't work. A few weeks before I learned about Windows Subsystem for Linux and my experience was great. If you are Linux pro stuck in Windows, this could be a relief. Basically, you can run a well designed minimal version of Ubuntu inside Windows 10.

In this article, we will get familiar with,
  1. Activation of Windows Subsystem for Linux.
  2. Installation of Ubuntu (no GUI) using Microsoft App Store.
  3. Configuring Python3, Pip3 and Jupyter Lab.
  4. Installation of R in Ubuntu and integration of R with Jupyter Lab.
  5. Installation of Julia in Ubuntu along with Jupyter Lab integration.
  6. Accessing Windows files with Ubuntu.

Installation of Windows Subsystem for Linux

Windows don't ship with WSL by default, we need to install it via PowerShell. 
Steps to follow,

1. Open PowerShell as Administrator and run following command.
"Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux"

2. Restart your computer after installation.

Installation of Ubuntu(minimal) from the Microsoft App Store.

Different Linux distros (like Ubuntu, Kali) are available in Microsoft Store. Right now we are going with Ubuntu.
1. Open the Microsoft Store and search for "Ubuntu".
2. Click on "Get", it will start downloading. After completion click on the "Launch" button and a bash equivalent will start running.
3. Let's do some initial setup, Enter a username and password for Ubuntu.
Configuring Python3, Pip3 and Jupyter Lab
1. Ubuntu on Windows got Python3 by default. Verify,
2. Upgrade Ubuntu to the latest. Shoot the commands,
"sudo apt update"
"sudo apt upgrade"
3. Time to install Pip3 from the repo, run the following in terminal,
"sudo apt install python3-pip"
4. Install Jupyter Lab using Pip3. 
"sudo pip3 install jupyter-lab"
Restart Ubuntu and check if  Jupyter Lab is running by typing "jupyter lab"
5. Copy paste the displayed URL starting with "http://localhost:8888/lab"  in a browser and check if Python is accessible.

The first part of our setup is over, let's proceed with R and Julia.

Installation of R in Ubuntu and integration of R with Jupyter Lab

Installing R and its libraries was a little tiring. I encountered with permission and dependency issues. So I'm suggesting to use R with sudo privileges and install some dependencies beforehand.
Few observed issues,

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
* rpm: openssl-devel (Fedora, CentOS, RHEL)
* csw: libssl_dev (Solaris)
* brew: openssl@1.1 (Mac OSX)
If openssl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a openssl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------------------------------------------------

ERROR: configuration failed for package ‘openssl’
* removing ‘/usr/local/lib/R/site-library/openssl’
* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lxml2
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libxml-2.0 was not found. Try installing:
* deb: libxml2-dev (Debian, Ubuntu, etc)
* rpm: libxml2-devel (Fedora, CentOS, RHEL)
* csw: libxml2_dev (Solaris)
If libxml-2.0 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libxml-2.0.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because openssl was not found. Try installing:
* deb: libssl-dev (Debian, Ubuntu, etc)
* rpm: openssl-devel (Fedora, CentOS, RHEL)
* csw: libssl_dev (Solaris)
* brew: openssl@1.1 (Mac OSX)
If openssl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a openssl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------------------------------------------------
ERROR: configuration failed for package ‘openssl’
* removing ‘/usr/local/lib/R/site-library/openssl’
* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lxml2
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libxml-2.0 was not found. Try installing:
* deb: libxml2-dev (Debian, Ubuntu, etc)
* rpm: libxml2-devel (Fedora, CentOS, RHEL)
* csw: libxml2_dev (Solaris)
If libxml-2.0 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libxml-2.0.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libcurl was not found. Try installing:
* deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
* rpm: libcurl-devel (Fedora, CentOS, RHEL)
* csw: libcurl_dev (Solaris)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------


1. Let's start with installing R, open Ubuntu and run specific apt command.
"sudo apt install r-base"
For some users, this won't work. In the case, please do an "apt update" and retry. Or for the official documentation - https://cran.r-project.org/

2. Check if R is installed correctly, press R in the terminal and see,
3. Before jumping into Jupyter Lab integration, install few dependencies that are needed.
"sudo apt install libssl-dev libxml2-dev libcurl4-openssl-dev"
4. Now, let's integrate R to Jupyter Lab, do the following steps sequentially,

  1. install.packages("devtools") 
  2. devtools::install_github("IRkernel/IRkernel") 
  3. IRkernel::installspec()

If you are getting any lock error(happens when installation got aborted) try with following params,
"install.packages("devtools", dependencies=TRUE, INSTALL_opts = c('--no-lock')) "


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Error in IRkernel::installspec() :
jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 127.
> The issue occurs when jupyter lab doesn't got sudo privilege but R has or vice versa.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

5. Check if R is integrated to Jupyter Lab, Restart Ubuntu and run "'jupyter lab"

The R part is over, now make Julia work,
Installation of Julia in Ubuntu along with Jupyter Lab integration
1. Goto https://julialang.org/downloads/, and copy the target link for Linux Binary. Use wget to download using Ubuntu terminal.
"wget https://julialang-s3.julialang.org/bin/linux/x64/1.1/julia-1.1.1-linux-x86_64.tar.gz"
2. Extract the zip file and create a soft link of "bin/julia" to "/usr/local/bin/julia". Please refer the attached screenshot or refer to this link - "https://stackoverflow.com/questions/41815059/installing-julia-v0-5-on-ubuntu-16-04-while-v0-6-is-installed"
Check if the installation is correct.
3. Let's integrate Julia to Jupyter Lab. The best resource I found is - https://datatofish.com/add-julia-to-jupyter/.
Get into Julia shell, and do these sequentially,

  1. using Pkg
  2. Pkg.add("IJulia")

4.  Let's see if Jupyter Lab can detect Julia, Restart Ubuntu and type "jupyter lab".
So, that's it. I hope everything is up. If you're stuck in any step, please comment below.
One more tip, which I found quite useful.
> In Ubuntu, the Windows partitions are available in /mnt/ directory. You can directly work on those files and duplication isn't needed. You may also consider adding you windows workspace folder to bashrc.


Comments

Popular posts from this blog

Setting up Python Flask server on internet via Port forwarding

In this post we will cover topics;

Starting a server using Python Flask.Accessing server in Local Network.Adding a Port Forwarding rule in NAT settings.Accessing server in Internet via public IP.Difference between static IP and dynamic IP.

Step 1 :-

As the first step, we need to setup a server on our system.A server exposes your code to a particular port.Some examples are Apache Tomcat, Spring boot (inbuilt), Python Django (inbuilt), Nginx.
Here we have a simple server in Python Flask.


For a GET request in root path the server returns a "Hello World!".That's it.
Going to start the server on my local IP address(192.168.1.105) at default flask port(5000) using below commands,
$export FLASK_APP=flaskTest.py
$flask run  --host=192.168.1.105



Step 2 :-

For security purpose all ports for external communication is closed by router's firewall by default. So no communication can be done to outside world. For same reason our server won't be available to other devices.
For our…

Automate Blog Post creation using Blogger APIs and Python

This article will discuss the following topics,

Blogger's REST APIs.Google's OAuth 2.0 playground.Accessing spreadsheet in Python.Creating blogger posts via Python.An experiment to automate blog post creation when you have structured data. I was searching for IFSC codes for some bank transactions and came across Reserve Bank's website, which has a list of excel files containing Bank Codes, Contact Info and related details of each bank's branch. This time I will be looking towards Bharat co-operative bank of Mumbai. Here is how the corresponding data looks like.
In the above picture, each row represents lots of details about each branch of the Bank. Let's think of creating a list of blog posts where each post gives IFSC codes of a particular branch along with address and contact details.

As the first step, I have created a blog in blogger. In the Blogger dashboard, Please also note the parameter called blog ID which is a kind of unique identifier to the blog. It is …

Creation of Orphan Process in Linux using Python

Hi all,

In this article we will learn about,
Orphan process in Linux/Unix.How orphan process is created ?Creation of orphan process using python.Usage of python modules - multiprocessing , subprocessOrphan Process :-

An orphan process is a child process whose parent got finished or terminated. After the termination of parent process, init process will adopt it.If you look into details, the parent pid(ppid) of an orphan will be 1 which is the pid of init. Sometimes orphan process is intentionally created for certain needs, like if you run an application and you don't want the process created by your application to be killed, even after closing the application.

Creation of Orphan process using Python :-

Here, we are going to create an orphan process through python code.
The logic behind the code is,

Create a process using python multiprocessing module and target function will be parent.
In parent function another process is spawned , making it's target function as child. Using su…