Installing Python on your development workstation
Documenting what I did to get my local Python development setup working:
Install pyenv
Note: 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.
To manage multiple versions of Python, install pyenv:
curl https://pyenv.run | bash
The output of this command tells you how to edit .bashrc
to load pyenv in your shell. Don’t forget to restart the terminal session.
If the command failed, you might need to install additional system packages that are required to build Python
Install a new Python version
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
Install Pipx
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
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.