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.12 on Ubuntu 22.04

python 3.12 installation

Ubuntu 22.04 ships with Python 3.10 by default. Since I needed Python 3.12 for newer features and compatibility, I installed it manually. Here’s how I safely set it up alongside the system Python.

Step 1: Update your system

sudo apt update
sudo apt upgrade -y

Step 2: Install Python 3.12 and tools

sudo apt install -y python3.12 python3.12-venv python3.12-setuptools python3.12-dev
  • python3.12: The main Python 3.12 interpreter.
  • python3.12-venv: Enables creation of virtual environments using python3.12 -m venv.
  • python3.12-setuptools: Provides tools to build and install Python packages (replacement for deprecated distutils).
  • python3.12-dev: Includes headers and libraries needed to build Python C extensions and compile native modules.

Step 3: Set python3 to point to Python 3.12

If your system still points to an older version, you can use update-alternatives to switch.

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 2
sudo update-alternatives --config python3

You will see a prompt like this:

There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.12   2        auto mode
  1            /usr/bin/python3.10   1        manual mode
  2            /usr/bin/python3.12   2        manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

Step 4 (Optional): Set the python command to point to Python 3.12

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 2
sudo update-alternatives --config python

You will see a prompt like this:

There is 1 choice for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.12   2        auto mode
  1            /usr/bin/python3.10   1        manual mode
  2            /usr/bin/python3.12   2        manual mode

Press <enter> to keep the current choice[*], or type selection number: 2


Step 5: Verify your Python versions

python3 --version
Python 3.12.3
python --version
Python 3.12.3

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)