Skip to content

Instantly share code, notes, and snippets.

@muellerzr
Last active September 23, 2021 14:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muellerzr/1011ac7e3d14a186e347f0d8ca97a62e to your computer and use it in GitHub Desktop.
Save muellerzr/1011ac7e3d14a186e347f0d8ca97a62e to your computer and use it in GitHub Desktop.
Explicit directions for how I setup Ubuntu Subsystem with conda, pip, python, and had it mounted from the D directory

Installing and configuring conda, jupyter, etc on wsl2

  1. Install Ubuntu from the Windows Store
  2. Setup changing the default opening directory (based on this)
    1. Open Ubuntu
    2. sudo vim /etc/passwd
    3. Type "i" to enter the insert mode so we can make changes
    4. Find your account's line, should start with your username. Eg mine was muellerzr:x:1000, :home/muellerzr/:bin/bash
    5. We care about changing the /home part. Change it to /mnt/c to use the "C" drive, /mnt/d to use the "D" drive, and so forth
    6. Save our changes with :wq and enter
  3. Exit and relaunch bash, this will now start where we want to

Editors Note: I made a jupyter folder and pointed mine to start there

  1. Installing Anaconda3 (Based on these instructions)

    1. Download this image of Anaconda3
    2. If working from a particular mnt drive, create your "jupyter" folder now. This is where we will install Anaconda and work out of
    3. From the terminal run sudo bash Anaconda3-2019.03-Linux-x86_64.sh.

    Editors Note: I have to include sudo on everything, due to read/write access for the D drive specifically and Ubuntu Subsystem. No solution yet.

    1. Read the licence agreement, and follow the prompts to accept.
    2. When it asks for an install/save directory, do not keep the defaults. Instead have it point to your jupyter folder we made. (this is relative to the install location for the most part)
    3. When it asks if you'd like the installer to prepend the path, say yes
    4. To confirm it worked, close the terminal and then run which python. It should print the python version. If it does not, we need to manually add it to the path a. vim ~/.bashrc b. Press i c. Add PATH=/mnt/d/jupyter/anaconda3/bin:$PATH d. This should point to your install directory of jupyter/anaconda3
    5. Finally, to have python work as python3, I did sudo apt install python-is-python3. Afterwards which python showed python3 by default
  2. Next, we need to install Jupyter and pypi. I changed the default installation of pypi packages to also be on my "D" drive, as it has more space and is an SSD

  3. Change the install location of pypi packages

    1. First update apt with sudo apt update
    2. Then install python3-pip with sudo apt install python3-pip
    3. Next, make a dist-packages directory in D:/jupyter/anaconda3
    4. Run pip config set global.target jupyter/anaconda3/dist-packages

    Editors Note: I'm yet to figure out how to tell pypi to download the Wheels file to here, more updates on this later

    1. I then also copied the contents of dist-packages originally and moved it over to our new one: sudo mv /usr/local/lib/python3.8/dist-packages/* D:/jupyter/anaconda3/dist-packages*
  4. Installing Jupyter

    1. Finally I had to reinstall jupyter, as the original jupyter package wasn't stored in the right location and there were some symlink issues
    2. sudo pip install uninstall jupyter-notebook
    3. sudo rm -r /usr/local/lib/python3.8/dist-packages
    4. sudo pip install jupyter-notebook
    5. sudo pip install jupyterlab
  5. Finally, a Conda environment based on this

    1. For my purposes I did conda create --name ENV_NAME but you just replace "ENV_NAME" with any name. You don't need to specify a python version, it will automatically use our default installed python3
    2. Finally do conda activate ENV_NAME before moving onto step 9
  6. Now we can start our server! In order to give Jupyter read/write access, we need to start our server with: sudo nohup jupyter notebook --port=8887 --allow-root > jupyter.log 2>&1 & echo $! > save_pid.txt

  7. Your server is now up! Simply copy the key and go to localhost:8887 to gain access

@muellerzr
Copy link
Author

Important Note:

To fix the sudo issue, move your location of the installed Ubuntu to the drive you're working on.

I followed the directions here: https://superuser.com/questions/1113906/can-i-move-the-linux-subsystem-to-a-different-drive

Note: The distribution name in this instance is Ubuntu rather than Ubuntu-18.04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment