Hop over the menu
The Red Pantry

A programming site about language and runtime versions

Move your libraries to Python's third major line first

Planning an upgrade

Editorial standards for these guides, including how The Red Pantry uses AI

The switch this guide covers

Your application is ready for a newer Python, but a library it depends on will not import there, and the switch stalls. This guide helps you find the libraries that block the move and the order to move them in. Moving a library means that every one of its dependencies installs, imports and passes its own tests on the interpreter you are moving to, before the application that calls it changes interpreter.

The advice behind the title is plain: upgrade your libraries to the newer major line of Python, according to RCC Python guide , and every line this guide covers belongs to that major line, so it does not cover porting code from the earlier one.

The setup for testing is short. For a newer Python interpreter, the RCC guide recommends uv, and it says you can set the line for a virtual environment with the --python MAJOR.MINOR flag, according to RCC Python guide .

TL;DR: move the libraries first, in dependency order; choose the target line by its security end date and drop date; clear removed modules before the switch; and pin the new line once the application runs on it.

Neat takeaways

  • Move libraries onto the target line before the application, because the application cannot run on a library that will not import.
  • Choose the target line from its security end date and from the date your libraries will drop the older line, not from release age alone.
  • A security-only line still receives security fixes but no new bugfix releases, so plan the move off it before its end date arrives.
  • Removed standard library modules can block the switch, so search for them before you change any version number.
  • Work through the libraries in dependency order, one environment per target, and keep the old line available for comparison.
  • Set requires-python and the version pin only after the new line passes your own test runs.

This is who this post is for

This guide fits developers and maintainers who run an application or a shared library on an older Python and must move a set of dependencies in a fixed order. It suits teams whose code runs under a continuous-integration pipeline, because the library checks described below are easiest to run there as separate jobs. It is less useful for a single script with no third-party dependencies, where the library steps have nothing to act on.

Red flags: a key library has no release that declares support for your target line; your code relies on a removed module and nobody owns the replacement; your deployment cannot change its interpreter at all.

Before the switch: choose the target line

Decide which line the switch is for before you change any file, because that choice sets how long the target will last. Follow these steps.

  1. For each Python line you are considering, check its security end date and status, according to endoflife.date .
  2. Rule out a line marked end of life, and treat a line marked security only as a stepping stone rather than a destination, since it gets security fixes but no new bugfix releases.
  3. Check what your libraries support, because room on the interpreter is only half the question and your libraries set the practical ceiling.

Before you move on, list each direct dependency and each dependency it pulls in, and write down the Python versions each one declares.

Library support windows and drop dates

An interpreter's security end date says when it stops getting fixes. Your libraries decide when you lose the ability to run an older line at all, because a maintainer who has stopped testing on a version will eventually release code that assumes a newer one. Check the line's drop date in the library support schedule, which dates when each Python line should stop being supported by the projects that follow it, according to scientific-python.org .

Use both dates together. The interpreter's security end date is the hard ceiling for the application, and the drop date is the practical ceiling for the libraries. A target whose drop date is close will force a second move soon, so a line that looks current today may be a short stop if most of your dependencies follow a schedule like this one.

During the switch: move libraries, then fix removals

Follow this recipe in order. Each library goes through the same steps before the next one starts, and the application is the last thing to change.

  1. Create one fresh virtual environment per library for the target line. The RCC guide's approach is to pick the line with the --python MAJOR.MINOR flag, for example uv venv --python MAJOR.MINOR , with your target line in place of the placeholder.
  2. Install the library into that environment and run its own test suite there, not on the old line.
  3. Search the library and your code for the modules in the removals table below, because a removed module can block the switch with a failed import.
  4. Replace each removed import with the replacement the table names, then rerun the suite.
  5. Release the moved library, pin it, and repeat from the first step for the next library in dependency order.
  6. Change the application's interpreter only after every library it depends on runs on the target line.

One removal to look for is distutils. The Python release notes record the removal of distutils, smtpd, asyncore and asynchat, according to Python documentation . The setuptools package includes a vendored copy of distutils, and its documentation lists replacements such as setuptools.setup for distutils.core.setup, according to setuptools documentation .

Other removed modules have named replacements too. An overview of modules removed from Python gives cgi.parse as urllib.parse.parse_qs, suggests a third-party module such as multipart for large cgi.FieldStorage payloads, replaces smtpd with aiosmtpd, pipes with subprocess, and asyncore and asynchat with asyncio, according to infoworld.com .

Removed module Replacement the cited sources name
distutils setuptools.setup in place of distutils.core.setup; the setuptools package vendors a copy
cgi (cgi.parse) urllib.parse.parse_qs
cgi (FieldStorage) a third-party module such as multipart for large payloads
smtpd aiosmtpd
pipes subprocess
asyncore, asynchat asyncio

A removed import usually fails at import time, so searching for removed modules is quicker than a full test run and catches the problem earlier. Treat the table as a starting point, not a full inventory, and check your own imports against each library's release notes.

After the switch: lock in the new line

Once the application runs on the target, record the line so that the next person does not fall back to the old one. Follow this recipe.

  1. Pin the project to the line you verified, for example with uv python pin MAJOR.MINOR or the equivalent command in your tool.
  2. Set only a lower bound for requires-python in pyproject.toml, at the oldest line you still test, with no upper cap, because a cap can leave users on newer interpreters silently falling back to old releases.
  3. Keep one continuous-integration job on the oldest line you still support until the last deployment has moved.
  4. Put the drop dates and security end dates you checked into your planning calendar, and treat each one as a scheduled move rather than a surprise.

Raising requires-python changes what installers offer. Users on an older interpreter then receive the newest release that still supports their interpreter, so announce the change in your release notes before you publish it.

Common mistakes

  • Porting the application before its libraries, which makes every import failure look like an application bug and hides the real blocker.
  • Choosing the newest line without reading each library's declared support for it, which leaves you with a dependency that will not install.
  • Treating a security-only line as the long-term target, which gives you a second move within a short time.
  • Missing a removed module because the code still runs on the old interpreter, so the failure appears only after the switch.
  • Raising requires-python before the libraries have run on the new line, which pushes users to older releases without a reason they can see.

Which Python line should you pick?

  • Pick the newest line that every key library supports.
  • Avoid a line marked end of life.
  • Treat a line marked security only as a stepping stone, not a destination.

FAQs

Should I move my libraries before the application?

Yes, because the application cannot run correctly on a library that will not import on the interpreter it is moving to. Move each library in dependency order, verify it in its own environment, and change the application's interpreter only after the libraries it depends on are ready.

Which Python line should I target first?

Target the newest line that every key library declares support for, and check its security end date on endoflife.date before you commit. If one library lags, the interim choice is the newest line that library still covers.

Does dropping an older Python line break users of my package?

It does not break the installs of users who already have it, but users on an older interpreter will be offered the newest release that still supports their interpreter. Say so in the release notes so those users know why the version they see has changed.

Is distutils still available in the standard library?

No, it has been removed. The setuptools package provides a vendored copy, and it recommends replacements such as setuptools.setup, so install setuptools and move your imports if you still need the functions.

Can I still use cgi on a newer Python?

Not on a line where the cgi module has been removed. Replace cgi.parse with urllib.parse.parse_qs and use a third-party module such as multipart for large form payloads, as the removals table describes.

How do I get a second Python line for testing without disturbing the first?

Use uv to create a separate virtual environment for each line, and specify the line with the --python MAJOR.MINOR flag. Keep each environment per library so a failure on one line does not contaminate the others.

Where do I check when a Python line stops getting fixes?

Check the release and security table on endoflife.date, which lists the security end date for each line. Compare that date against the drop dates in the library support schedule before you decide how long the target line will last.

Read next

General information about language versions, not legal or contract advice.

Browse more guides