pyenv-virtualenv on Ubuntu/Pop!_OS

17 July 2022

Below is how I set up pyenv-virtualenv on Ubuntu/Pop!_OS (Pop!_OS 22.04 LTS x86_64), with jupyter-lab set up with such pyenv-virtualenv for good measure.

sudo apt-get install git python3-pip make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl libncurses-dev libffi-dev liblzma-dev tk-dev

git clone https://github.com/yyuu/pyenv.git ~/.pyenv
git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
exec $SHELL

To see available python versions:

pyenv install --list

Installing the latest available at the time of typing:

pyenv install 3.10.4
pyenv virtualenv 3.10.4 base
pyenv activate base

Now let’s get poetry

sudo apt install python3-poetry python3-cachecontrol
poetry config virtualenvs.create false

Now let’s get poetry started in whatever folder we are using for base

poetry init

Fill that out leaving as much of it blank/default as you like

poetry add jupyterlab

And of course jupyterlab wants nodejs on the system so

sudo apt install nodejs

And we want to make the base kernel available within jupyter (note the below should be run with the pyenv active):

python -m ipykernel install --user --name base

References