Checking module compatibility before upgrading?

Hello,

To make sure things don’t break after upgrading Python, is there a command to check that all the modules currently installed will keep working?

I’ve seen this command. Is it reliable?

#run before upgrading!
pip3 freeze > python_requirements.txt

#dry run
python -m pip install -r python_requirements.txt --dry-run --python-version 3.13.1 --no-deps --target foo | grep ERROR

Incidently, can the installer be told to download and install all the modules, so that the user doesn’t have to know/remember to run the “pip3 freeze” command beforehand?

Thank you.

Maybe I’m wrong, but I think you should not run the first command. It will store the current packages in python_requirements.txt. The second command will simulate the install reading from python_requirements.txt. If you overwrite it with your current packages, it will succeed every time.

You should run only the second command with the new python_requirements.txt

The --python-version argument to pip will make it evaluate the dependencies in the context of the given Python version, so it should fail if something in the current set of packages is incompatible with the given version (3.13.1 in the example).

2 Likes

Check out this project of mine: GitHub - hauntsaninja/python_readiness: Are your dependencies ready for new Python?

2 Likes

Thanks for the link. I’m suprised Python didn’t already have something available for such a common need.

pip install python_readiness
pip freeze > python_requirements.txt
python_readiness -r python_requirements.txt --python 3.13