Wietse Venema's blog


Installing Python on your development workstation

Noting down what I did to get my local Python development setup working:

Python

To manage multiple versions of Python, install pyenv:

curl https://pyenv.run | bash

Edit .bashrc to load pyenv in your shell (and restart the terminal session)

Note that if your OS has a recent enough version of Python you might not want to bother with pyenv. I chose pyenv because I wanted to have a more recent version than what was distributed with my OS.

Install a recent version of Python (as of April 2024):

pyenv install 3.11
pyenv global 3.11

Verify the version of Python you’re now running is 3.11:

python --version

To install Python apps like poetry in their own virtual environment, install pipx:

python -m pip install --user pipx
python -m pipx ensurepath
pipx ensurepath

Note that pipx uses the Python version it was installed with, in this case 3.11. It’ll continue doing that even if you switch to a different version of Python with pyenv later.

Install poetry for dependency management. It has a lockfile to keep your transitive dependencies in check.

pipx install poetry

Update the poetry settings to create the project virtual environment in the project directory

poetry config virtualenvs.in-project true

Visual Studio Code

Install the Python extension

Because poetry creates the .venv in the project dir, your terminals in VS Code should pick up that environment automatically, and the debugger uses it too. You might have to restart VS Code for that to work.