Skip to content

Instantly share code, notes, and snippets.

@friscojosh
Last active October 13, 2022 16:51
Show Gist options
  • Save friscojosh/66328c18dbee9095145e3ee7b15ecb7c to your computer and use it in GitHub Desktop.
Save friscojosh/66328c18dbee9095145e3ee7b15ecb7c to your computer and use it in GitHub Desktop.

14. Set up a Python Development Environment

Install pyenv

Prerequisites for pyenv

sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

Troubleshooting guide here.

`curl https://pyenv.run | bash

Open .bashrc and add the following lines to the end:

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

eval "$(pyenv virtualenv-init -)"

exec $SHELL

Test that things work:

pyenv --version

Install python pyenv install 3.9.15

Latest version can be found here.

Set the global interpreter: pyenv global 3.9.15

Check the global python version: which python It should read: /home/josh/.pyenv/shims/python

Install pipx

Overview: What is pipx?

pipx is a tool to help you install and run end-user applications written in Python. It's roughly similar to macOS's brew, JavaScript's npx, and Linux's apt.

It's closely related to pip. In fact, it uses pip, but is focused on installing and managing Python packages that can be run from the command line directly as applications.

How is it Different from pip?

pip is a general-purpose package installer for both libraries and apps with no environment isolation. pipx is made specifically for application installation, as it adds isolation yet still makes the apps available in your shell: pipx creates an isolated environment for each application and its associated packages.

pipx does not ship with pip, but installing it is often an important part of bootstrapping your system.

python3 -m pip install --user pipx

python3 -m pipx ensurepath

Upgrade pipx using: python3 -m pip install --user -U pipx

Install poetry

curl -sSL https://install.python-poetry.org | python3 -

Guide here.

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