Skip to main content

WSL

A few notes on setting up WSL, Pyenv, and Poetry. We use river-ice-ingester as an example repository.

I removed the .bash_profile file and added the final few lines starting with # set PATH to include pyenv to the .profile file:

# ~/.profile: executed by the command interpreter for login shells.# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login# exists.# see /usr/share/doc/bash/examples/startup-files for examples.# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask# for ssh logins, install and configure the libpam-umask package.#umask 022
# if running bashif [ -n "$BASH_VERSION" ]; then    # include .bashrc if it exists    if [ -f "$HOME/.bashrc" ]; then    . "$HOME/.bashrc"    fifi
# set PATH so it includes user's private bin if it existsif [ -d "$HOME/bin" ] ; then    PATH="$HOME/bin:$PATH"fi
# set PATH so it includes user's private bin if it existsif [ -d "$HOME/.local/bin" ] ; then    PATH="$HOME/.local/bin:$PATH"fi
# set PATH to include pyenvif [ -d "$HOME/.pyenv/bin" ] ; then    PATH="$HOME/.pyenv/bin:$PATH"    PATH="$HOME/.pyenv/shims:$PATH"fi
# set PATH to include poetryif [ -d "$HOME/.local/bin" ] ; then    PATH="$HOME/.local/bin:$PATH"fi
# Better colors for command line interfacesexport TERM=xterm-color

Those final lines check if /home/birvap/.pyenv/bin exists. If so, it adds that directory to the PATH environment variable. When invoking a command (e.g. pyenv or ls, etc.) your shell checks the directories in the PATH variable from left to right until it finds an executable that matches the command name (e.g. /home/birvap/.pyenv/bin/pyenv or /bin/ls ). You can check the location of the executable found in PATH with which:

$ which pyenv   
/home/jthetzel/.pyenv/bin/pyenv

Your shell, bash (Bourne Again Shell), first looks for a .bash_profile file. If not found, it reads from .profile . Prior to bash, there was sh (Bourne Shell). .profile can be used by both bash and sh. I tend to put PATH logic in .profile to keep things simple. But you're welcome to create a .bash_profile and put it there is you prefer. Here is a stackoverflow thread on the difference between the two file, which you might have aready read: https://unix.stackexchange.com/questions/45684/what-is-the-difference-between-profile-and-bash-profile . These PATH updates were supposed to happen automatically when installing pyenv. Not sure why they did not. Anyway, after updating .profile , run it to update your path:

source ~/.profile

Then confirm pyenv is available:

$ which pyenv
/home/jthetzel/.pyenv/bin/pyenv

You can check which shell you are using or switch to a different shell:

$ echo $0-bash
$ sh
$ echo $0sh
$ exit
$ echo $0-bash

The directory structure in Ubuntu tends to follow the Filesystem Hierarchy Standard ( https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard ).

I like to keep c-core source code namespaced, so I would

mkdir ~/src/c-core-labs

But, organize your directories however you prefer. Then, depending on how you access github, either:

cd ~/src/c-core-labsgit clone git@github.com:c-core-labs/river-ice-ingester.git

or

cd ~/src/c-core-labsgit clone https://github.com/c-core-labs/river-ice-ingester.git

If you haven't setup ssh key access and are interested, follow these instructions: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account (but you don't need to)

Before installing python with pyenv, you need to have a C compiler available. The easiest way is:

sudo apt install build-essential

which includes gcc and g++ (https://packages.ubuntu.com/focal/build-essential ). You will also need a few additional dependencies for building python:

sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev

Due to an upstream SSL bug, river-ice-ingester had to downgrade to python 3.7 (see the Dockerfile: https://github.com/c-core-labs/river-ice-ingester/blob/master/Dockerfile#L1 ). That bug might be resolved in python 3.9 or 3.10, but I haven't checked yet. So, for now, we can install python 3.7.12 (which is the latest 3.7.x):

pyenv install 3.7.12

And set it as the default python:

pyenv global 3.7.12

You can set local (directory specific) python version with:

pyenv local 3.7.12

However, there is a recent known regression pyenv local and poetry (https://github.com/python-poetry/poetry/issues/4199). There is a fix in preview (https://github.com/python-poetry/poetry/pull/4852), but I have not tried it yet. We'll stick with 3.7.12 in the meantime to keep things simpler. (edited)

Before installing river-ice-ingester, you will also need to install spatialindex, which geopandas uses for improved spatial filtering efficiency.

sudo apt install cmake -y
wget https://github.com/libspatialindex/libspatialindex/releases/download/1.9.3/spatialindex-src-1.9.3.tar.gz && \tar -xvzf spatialindex-src-1.9.3.tar.gz && \cd spatialindex-src-1.9.3 && \cmake . && \make && \sudo make install && \cd - && \rm -rf spatialindex-src-1.9.3* && \sudo ldconfig && \cd ../.. && \rm -rf spatialindex*

You also need to install the Google Cloud SDK. Follow instructions from https://cloud.google.com/sdk/docs/install .

Then login with

gcloud auth login

followed by a

gcloud config set project c-core-labs

Then you can:

gsutil cp gs://c-core-labs/config/river-ice-ingester/.env .gsutil cp gs://c-core-labs/config/river-ice-ingester/firestore.json .

Finally, you'll need to install tippecanoe (https://github.com/mapbox/tippecanoe). This is used to convert geojson to mapbox vector tiles.

git clone https://github.com/mapbox/tippecanoe.git && \cd tippecanoe && \make && \sudo make install && \cd .. && \rm -rf tippecanoe