35

Setting up a Python Data Science environment using Windows Subsystem for Linux (...

 4 years ago
source link: https://www.tuicool.com/articles/VFNR3ya
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Setting up a Data Science environment using Windows Subsystem for Linux (WSL) and Jupyter

V7RZbar.jpg!webn2YNZjf.jpg!web

We’ve all felt the terror and unrest when trying to install something on a machine we don’t have admin rights on. Likewise we’ve all felt the powerlessness associated with a Linux-only applications which we couldn’t run on our windows machine. Fear no more, WSL is here to save the day!

What we’ll be doing:

  • Setting up WSL (with optional ZSH and Oh-my-zsh )
  • Setting up Anaconda .
  • Setting up a customizable Jupyter Notebook environment.

Please enjoy. I hope you find it useful. Make sure to follow my profile :mag: if you enjoy this article and want to see more!

First off we have to do some preliminary setup to get WSL working:

1 — Turning on ‘Developer mode’

First head to the developer settings in your Windows 10 settings menu: Settings ➡ Update & Security ➡ For developers ➡ Developer mode

Or simply search for the term “ dev ” and click on “ Developer settings

mQryUnr.png!webNVzER3e.png!web

Here you might need to sign into an admin account or get temporary access to turn on the Developer mode:

36jaiaQ.png!webaQrQjuf.png!web

Once enabled we need to turn on the Windows Subsystem for Linux feature.

2 — Turning on ‘Windows Subsystem for Linux’

This menu can be accessed as such by going to: Control Panel ➡ Programs ➡ Turn Windows features on and off

Or simply search “ windows features ” and click on “ Turn Windows features on or off

mAFZNnJ.png!webqAfA7vE.png!web

Next make sure the feature “ Windows Subsystem for Linux ” is ticked:

MBNZVj2.png!webueIjYzj.png!web

3 — Restart your computer!

4 — Installing Ubuntu

Simply head to the Microsoft Store and search for “ Ubuntu ”, select the App (ugh..) you prefer and install it on your machine:

IBj6Jrm.png!webuI3Yriv.png!web

When first launched you’ll be prompted to enter a UNIX username and password , choose whatever you see fit.

Congratulations, you now have a fully functional Linux Subsystem in which you have full admin rights!

Personally I don’t really like the look of the default terminal so I would recommend following this to install ZSH and Oh-my-zsh if that’s your cup of tea:

Setting up Anaconda

1 — Downloading Anaconda

Start up your newly configured WSL and download Anaconda:
wget <a href="https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh" data-href="https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh" rel="nofollow noopener" target="_blank">https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh</a>

2 — Installing Anaconda

Next, execute the downloaded file to install Anaconda:
Anaconda3-2019.03-Linux-x86_64.sh

NB: Use “bash Anaconda3–2019.03-Linux-x86_64.sh” if using ZSH and you’re running into problems.

After following the onscreen instructions to install Anaconda, simply remove the installation file:

rm Anaconda3-2019.03-Linux-x86_64.sh

3 — Updating Anaconda

Now you should be able to start up your Anaconda environment:
source ~anaconda3/bin/activate

“~anaconda3/bin/activate” is default place that Anaconda will install itself but if you chose elsewhere simply point to that directory.

Once activated, initiate a full update:

conda update --all

4 — Done..!

Once updated, lean back and gaze upon your creation and see that it is good…

You’ve successfully set up a Windows Subsystem for Linux with Anaconda 3!

Setting up your Jupyter Notebook environment

This is pretty straight forward since Jupyter is native to Anaconda, so if you’re happy with the default Jupyter Notebook interface / environment then you’re already done! Simply launch a notebook by using the following command once you’ve activated your Anaconda environment:

jupyter notebook

The WSL instance should automatically launch a window connected to the Notebook, but if that isn’t the case simply find the host address in the WSL terminal which looks something like this: “ http://localhost:8888/tree?token=someprettylongtokenhere” and copy that into your browser of choice.

Customising Jupyter Notebook

I’ll go over two main ways you can customise your Jupyter Notebook experience, Nbextensions and Themes , jump to whatever section you find relevant to you.

1 — Setting up extensions

Thankfully this is pretty easy as well, simply run the following command to set up the nbextensions package and restart your notebook:

pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install

Next you’ll be presented by a new tab when you launch your notebooks called “Nbextensions”

neiMJzJ.png!webiU3UbiE.png!web

Now you can simply pick and chose what plugins you want / need and customise to your hearts content. The interface also supplies you with a screenshot and description of each extension so you can gauge whether you want to enable it or not.

I specifically recommend the following:

  • Hinterland — For easier auto-correction.
  • Table of Contents (2) — For automatically generating a ToC from your Markdown headings and sub-headings.
  • Toggle all line numbers — For easier debugging.
  • Variable Inspector — For an R-like variable overview, really useful!
  • ExecuteTime — For timing your cell executions.
  • Autopep8 — For automatically formatting your code to pep8 standards.
  • Collapsible Headings — For easy hiding of parts of your notebook.

That’s it! If you feel like this wasn’t enough to quench your interest in extensions I can highly recommend the following article on the same subject:

2 — Setting up themes

Personally I’m using this package from dunovank on GitHub:

To install this package simply run the following:

pip install jupyterthemes

Next initiate your theme of choice dark or light (Please refer to the GitHub link for customisation options) by simply running one of the following commands:

# "Default" settings for dark and light themes
# DARK
jt -t onedork -fs 95 -altp -tfs 11 -nfs 115 -cellw 88% -T
# LIGHT
jt -t grade3 -fs 95 -altp -tfs 11 -nfs 115 -cellw 88% -T

I prefer the dark theme, which makes your notebook look something like this:

6vE7jiV.png!webAnYzeaf.png!web

That’s it! You’re done. Enjoy your new environment!

Thanks for reading, I hope it was useful for you. Please leave a comment if you feel like I left something important out or if you simply want to leave some feedback for me! Also, make sure to follow my profile :mag: if you enjoyed it and want to see more!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK