Python

Tips and tricks for working with Python

Overview

  • As Python gets updated, older code will cease to run due to changes in Python syntax and functionality

  • To resolve this, we can run code in containers, but that adds a level of complexity

  • Another solution is to use uv (or pyenv and pipx) and run the code in virtualized environments with the required version of Python

Installation

brew install uv

View Available Python Versions

List all available python versions (both installed and not)

uv python list 

List only installed python versions

uv python list --only-installed

List only python versions not already installed

Using Specific Python Versions

Install one or more versions of python

Install a tool with a specific python version

Set up a Virtual Environment

Creates a virtual environment with python v3.14.0

Installing Required Modules

Managing Tools Installed with uv

List installed tools

Install tools

  • This works just like pipx or pip

Uninstall tools



Old β€” Examples

Old β€” Install and Run a Python App with a Specific Python Version

  • PrincipalMapper (pmapper) is a tool that requires Python version 3.9 to run (it errors out otherwise)

Old β€” Set up a Python Virtual Environment

  • We can set up a virtual environment to run any version of Python we want

  • This is useful for isolating your Python code/packages without impacting your system configuration

Parsing JSON

View installed modules

View pip modules


Old β€” Pyenv

Installation

  • pyenv is a useful tool for letting us quickly download and switch between multiple versions of Python

  • Full installation instructions can be found here

Useful commands


Old β€” Pipx

Installation

  • pipx is a useful tool for installing and running python code and apps in isolated virtual environments

  • Full installation instructions can be found here

Useful commands

Last updated

Was this helpful?