Setting up WSL : Linux for Windows and Anaconda, Ubuntu, VS Code.

Setting up WSL : Linux for Windows and Anaconda, Ubuntu, VS Code.
Antarctic penguins, from wikimedia commons.

It can feel chilly way-finding through set-up without a clear path. Before I can dive into machine learning with DataTalks.Club, I have the set-up learning curve. Thankfully, I already work with Python, VS Code, GitHub and Anaconda, but Linux is new. Oh! how I knew this day was coming that I would inevitably cross-paths with Linux. Machine learning has lead me here.

So. Where does one start? What is the end result? Thinking spatially, how is this all arranged?

WSL is a pseudo-partitioning of the computer or a separate drive-space that runs Linux. The end goal is to have a scripting environment in Linux that can connect VS Code, GitHub, and run Jupyter notebooks, Kaggle notebooks, and Google Colab. Later on, I'll add Docker. WSL is that parallel workspace or environment and VS Code, with the right extension, can reach into this environment. Within WSL, we set up the environment akin to a specialized container garden.

How do I get there?

Install WSL for Windows (Ubuntu).

  1. This can be done either through the browser or use the Windows command line:
wsl --install
  1. Instructions from Microsoft
  2. Set up Linux username and password. Be careful typing these in! I had a mistype and had to reset my credentials later on.

Install VS Code and WSL extension

  1. Get most recent version. Microsoft docs on VS Code and WSL are helpful.
  2. Fun part! Install the extensions :
    1. WSL,
    2. Remote working extensions from MS,
    3. Jupyter extensions,
    4. Python & Pylance extensions,
    5. GitHub codespaces & GitHub Pull Requests,
    6. markdownlint,
    7. Data Wrangler, and
    8. Dracula. Or whichever easy-on-the-eyes code theme works for you.

I also enjoy indent-rainbow, JSON beautify, Rainbow CSV.

Later on I'll need all the Docker related extensions.

  1. Launch VS Code from within the WSL environment. From the Ubuntu terminal type:
$ code .

Alternatively, open VS Code via Windows and select REMOTE WSL from the command palette (CTRL+SHIFT+P)

Also, you'll want to install Git in WSL.

Install Anaconda within WSL via Ubuntu Terminal

  1. Find latest version of Anaconda.
  2. Select Linux version that matches your specs. I chose x86_64.sh :
Anaconda3-5.2.0-Linux-x86_64.sh
  1. In the Ubuntu terminal, obtain the files:
$ wget https://repo.continuum.io/archive/Anaconda3-5.2.0-Linux-x86_64.sh
  1. Install the files:
$ bash Anaconda3-5.2.0-Linux-x86_64.sh

5 Type 'yes' for license agreement. I don't recommend installing VS Code at this step (prompted), but rather as a separate installation.

6 Close terminal and reopen. This reloads the .bash configs.

7 Test that it worked by typing $ which python. If the file path is not displayed, then you'll need to add the Anaconda bin folder to the PATH.

8 Locate the /.bashrc file for Anaconda3. At the bottom of the file, add the path directly:

export PATH=/home/YOUR-USER-NAME/anaconda3/bin:$PATH

9 Open a Jupyter notebook by typing $ jupyter notebook --no-browser. This will provide you with the token to run Jupyter on port 8888 in your browser, but won't automatically pop open the notebook.

10 Test that Anaconda is functioning by using a 'conda' prompt in the terminal. If conda is not recognized, first close/open terminal. If that doesn't work, then confirm if Python is installed.

$ python3 --version

Create environments within Anaconda and activate them

Good idea to have separate environments for each type of work.

Create the environment - replace python version with your version:

conda create -n ml-learning python=3.6

Activate:

conda activate ml-learning

Install libraries!

conda install numpy pandas scikit-learn seaborn jupyter

Troubleshooting

bzip2 not installed error

Run

$ sudo install bzip2

Close and reopen the terminal. Re-run the install.

Anaconda3 directory already exists

This potentially happens at this stage of installation:

Anaconda3 will now be installed into this location:
/root/anaconda3

– Press ENTER to confirm the location
– Press CTRL-C to abort the installation
– Or specify a different location below

You can specify a different location and/or you can remove the already-written directory and start a fresh installation. One could chose to move the package, but it was easier just to delete and re-run the installation.

Removing the existing directory:

rm -rf ~/anaconda3

Anaconda's docs on uninstalling

Reset Ubuntu password

Halp! I mistyped my password initially and I have no idea what I blind typed.

Reset by typing:

passwd >yourusername<

You'll be prompted to enter a new password twice.

Install Python

This works for Ubuntu 16.10 or newer:

$ sudo apt-get update
$ sudo apt-get install python3.6

Install Pip

Pip is a great pal! Pip manages those install files.

Check if pip is installed :

$ command -v pip

Pip install docs have all the details, but most-often ensurepip module can install pip in a Python environment.

$ python -m ensurepip --upgrade

Thanks to kauffmanes, whose documentation helped with the Anaconda install.