Introduction

Since January 1st, 2020, Python 2 is no longer maintained by the Python Software Foundation, and its time in Oracle Solaris is also coming to an end.

It has been more than a year now since we migrated the entirety of Oracle Solaris from Python 2 to 3. Currently, every relevant Python 2 component in Oracle Solaris is also available for Python 3, and for some time now, new components have been added as 3 only. And with the release of Oracle Solaris 11.4 SRU 57, Python 2 will be obsoleted completely.

What will change

With the installation of SRU 57 (or later), the Python 2.7 runtime and all *-27 variants of Python packages will be removed from your system. Several Python components are delivered in *-27 variants only – those will be removed as they are now part of the standard library.

As for the /usr/bin/python link, its default location was changed to /usr/bin/python3.7 in SRU 30 and later to /usr/bin/python3.9 in SRU 54, but if you explicitly set it yourself to 2 or you are moving from an older SRU, this will also affect you. The same applies to tools such as pydoc, idle, or python-config. As for /usr/bin/python2 and /usr/bin/python2.7, they will both be removed.

If you are executing Python scripts directly with hashbang interpreter directive such as #!/usr/bin/python2.7, #!/usr/bin/python2, #!/usr/bin/env python2 or #!/usr/bin/env python2.7, those scripts will stop working and you will have to change all those lines to newer available Python version manually.

What will not change

While the lifetime of Python 2 is coming to an end, Python 3 is fully supported! In fact, Python is one of the most crucial FOSS component of Oracle Solaris, and we are fully committed to its support for years to come. One such example is the recent integration of Python 3.11 to Oracle Solaris that just came out in SRU 54.

We are also not removing any additional components using Python in the backend (such as subversion, mercurial, or pidgin) except for those currently marked legacy or useless in newer versions of Python.

Migration from Python 2 to Python 3

If your software still uses Python 2, we strongly recommend you to migrate it to Python 3 if possible. The first thing is to check with the application vendor to see if there is a later version that supports the newer version Python; if so, consider updating to that later version.

If you are migrating the code yourself, you can refer to the official porting guide maintained by the Python upstream. You can also find additional guides and migration resources online.

There is also 2to3, a tool for automated 2 to 3 code translation tool. While not perfect, it can help you with the initial ‘rough pass’ and, in some cases, do the complete migration for you! It is delivered with each Python runtime on Oracle Solaris, hence you can start using it right now.

Keeping Python 2

If your software still depends on Python 2.7, and you cannot get a newer version of such software that works with Python 3, you have two options:

Option 1

The first option is to ‘freeze’ currently installed Python 2.7. While Oracle Solaris IPS will, by default, keep the system up-to-date and with an upgrade to SRU 57 remove Python 2.7, you can prevent it from doing so by unlocking its version-lock* and freezing it to the currently installed version.

*) This is necessary as otherwise IPS won’t let you install the version of the package that doesn’t correspond to the current SRU.

In order to help you with that, we recently delivered /usr/sbin/freeze-python2.7 script that will do everything necessary for you and freeze all packages that are currently installed on given machine and depend on runtime/python-27 package. If you want to keep just a subset of those, the simplest way is to uninstall those before using this script.

You can, however, manually freeze and unfreeze additional packages later with the following:


# unlock library/python/cffi-27
pkg change-facet version-lock.library/python/cffi-27=false
# install the package if it's not already installed
pkg install library/python/cffi-27@1.15.0-11.4.54.0.0.139.0
# freeze the package
pkg freeze -c 'Legacy Python 2.7 Environment' library/python/cffi-27

Be aware that this process is not 100% future proof, and if ABI of libraries Python 2.7 links against changes, frozen packages will stop working.

Please note that while this script was delivered for some time now, due to a bug we discovered later you have to run the version that is available in SRU 54 or later.

More general information on keeping older software can be found here.

Option 2

The second option is to build Python 2.7 runtime yourself. Doing so will allow you to use the latest versions of shared libraries python links against (unless it won’t support it), and you won’t have to freeze many packages to use it. Still, even this approach won’t let you use Python 2.7 infinitely as future changes to Oracle Solaris FOSS might result in some features of 2.7 not being available anymore (for example the SSL support due to the eventual removal of all OpenSSL versions older than 3.0).

If you want to build Python 2.7 yourself, you might find the Userland repository on GitHub useful as it includes additional patches and Makefile we use to build it. You can find the source just before it was removed here.

No matter what approach you choose, we strongly encourage you to migrate to Python 3 if possible. Python 2 won’t get any additional security fixes from either the community or Oracle Solaris, and its general support is only getting weaker.

Additional resources

[1] Sunsetting Python 2 (upstream)
https://www.python.org/doc/sunset-python-2/

[2] Trapped by Older Software
https://blogs.oracle.com/solaris/post/trapped-by-older-software

[3] Oracle Solaris Userland gate GitHub mirror
https://github.com/oracle/solaris-userland/

[4] The official Python porting guide
https://docs.python.org/3/howto/pyporting.html

[5] Automated Python 2 to 3 code translation
https://docs.python.org/3/library/2to3.html