Managing FastAPI Projects with Poetry: A Step-by-Step Guide

Image
This guide will walk you through how to use Poetry to manage dependencies and structure your project in FastAPI . It includes detailed explanations of Poetry's core concepts and commands to help prevent issues that can arise during team collaboration and deployment. 1. What is Poetry? Poetry is a dependency management and packaging tool for Python. It goes beyond simply installing libraries by allowing you to clearly declare the dependencies your project needs and ensuring that all developers on the project have the same library versions. Clarity in Dependency Management : Explicitly manage your project's basic information and required libraries through the pyproject.toml file. Reproducible Builds : By locking all dependency versions in the poetry.lock file, it fundamentally prevents "it works on my machine" problems. Integrated Development Environment : It automatically creates and manages isolated virtual environments for each project and handles mo...

How To Install Python 3.10 on Ubuntu 24.04 for pyannote.audio Compatibility

python 3.10

I'm currently working with pyannote.audio version 3.1.1, and for full compatibility, it requires Python 3.10—especially because it was trained with torch==1.13.1 and CUDA 11.7. But by default, Ubuntu 24.04 ships with Python 3.12, and that caused some issues with dependencies.

Python 3.10 Isn’t Included in Ubuntu 24.04

Ubuntu 24.04 (codename: noble) only comes with Python 3.12 by default.

When I tried to install Python 3.10 using just sudo apt update, the package simply couldn’t be found—because it isn’t included in the official package repositories.

To install Python 3.10, I had to add the deadsnakes/ppa.

This is a reliable third-party repository that provides older or alternative Python versions not offered in Ubuntu’s official repositories.
# Add the Deadsnakes PPA
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt update

# Install Python 3.10 and related tools
$ sudo apt install python3.10 python3.10-venv python3.10-dev \
                 python3.10-distutils python3.10-gdbm python3.10-tk

Compiling Python 3.10 from Source (Alternative Option)

If you’d rather compile Python 3.10 yourself—say, to get the latest patch like 3.10.14—you can do that too. I tested this approach and it worked well, though it takes more time and effort.

This installs Python 3.10.14 alongside the default Python, so it won’t interfere with your system installation.

$ sudo apt update
$ sudo apt install -y software-properties-common 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

$ cd /usr/src
$ sudo wget https://www.python.org/ftp/python/3.10.14/Python-3.10.14.tgz
$ sudo tar xvf Python-3.10.14.tgz
$ cd Python-3.10.14
$ sudo ./configure --enable-optimizations
$ sudo make -j$(nproc)
$ sudo make altinstall

Creating a Virtual Environment

After installing Python 3.10, I created a virtual environment to keep my dependencies isolated. This is how I set it up:

# Create a virtual environment with Python 3.10
$ python3.10 -m venv pyannote_env

# Activate the environment
$ source pyannote_env/bin/activate

This way, I could run pyannote.audio with the exact versions of torch, transformers, and other libraries it expects—without affecting my global Python setup.

Uninstall Python 3.10 (Installed via make altinstall)

I didn’t know that I could install Python 3.10 via apt install by adding the ppa:deadsnakes/ppa repository, so I initially built it from source using make altinstall. Later, I realized it would be harder to manage, so I removed it manually by deleting the files under /usr/local/.

This does not affect your system’s default Python (e.g., Python 3.12 on Ubuntu 24.04).


# Main binary and config
sudo rm -f /usr/local/bin/python3.10
sudo rm -f /usr/local/bin/python3.10-config

# Standard libraries
sudo rm -rf /usr/local/lib/python3.10

# Header files
sudo rm -rf /usr/local/include/python3.10

# Man pages
sudo rm -rf /usr/local/share/man/man1/python3.10.1

# Extra binaries
sudo rm -f /usr/local/bin/pip3.10
sudo rm -f /usr/local/bin/idle3.10
sudo rm -f /usr/local/bin/2to3-3.10

# Source folder (optional)
sudo rm -rf /usr/src/Python-3.10.14

Comments

Popular posts from this blog

Resolving Key Exchange Failure When Connecting with SecureCRT to OpenSSH

SecureCRT] How to Back Up and Restore SecureCRT Settings on Windows

How to Set Up Vaultwarden (Bitwarden) on Synology NAS (Best Free Alternative to LastPass)