4. Updating dependencies, part one: the easy wins

Your application is already on the way to reach full Python 3 compatibility, but the issue of its dependencies still remains.

It’s not uncommon for projects to accumulate dependencies that are no longer maintained and consequently lack Python 3 support.

In some cases, all you’ll need to do is update a dependency to a newer version; in others, you’ll have to make sure the update is the latest version, compatible with both Python 2 and 3. That’s because certain packages may have already dropped Python 2.

Regardless, at this point, it’s best to concentrate on the easy wins.

Most of your packages are likely already compatible or only require an update to a newer version. As a rule of thumb, we suggest updating to the latest release of each dependency to be on the safe side.

Checking each dependency one by one can be time-consuming in larger projects. You can facilitate the process by running “caniusepython3” on your “requirements.txt” (create one with “pip freeze > requirements.txt” if you don’t have one).

This tool is far from accurate, but it’s good enough to achieve our main goal here: assessing how much work remains before you can make the final switch to Python 3.

Python 3-compatible forks

It isn’t unusual to learn that a package has been completely abandoned by its original authors. However, it’s still a good idea to browse through the package’s GitHub repository issue tracker or PyPI index, since others have likely encountered the same issue as you and already created a fork compatible with Python 3.

If you’re unable to identify a working Python 3 package replacement, postpone upgrading or replacing it to a later stage. You have bigger fish to fry.

Dealing with backports

Some of the features added to Python 3 have been backported as separate installable packages. Popular examples of this include “subprocess32” and “functools32.”

These backports tend to be incompatible with Python 3 and will fail if you even attempt to install them. You can use environment markers to make sure that doesn’t happen.

Here’s how you can carry out a conditional installation of “functools32,” only on Python 2:

functools32; python_version < "3"

This syntax can be applied to both “requirements.txt” and “setup.py.”

When it comes to the code, use a “try-except” syntax for such packages: