Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers!
With SPSS Statistics V27, Python 2.7 is no longer provided by IBM, because it has reached the end of its support lifetime from the Python Software Foundation, and that means no more minor version updates if security issues are discovered. (This is extremely unlike to be an issue with Python used with SPSS, but, whatever.)
You can still install Python 2.7 from the PSF site and then set Statistics to use that external Python distribution via Edit > Options >Files, but it would be better to switch to Python 3. V27 supports Python 3.8. V24 was the first version to support Python 3.
However, that requires converting Python 2 code to Python 3, since they are not entirely compatible, and changing the BEGIN PYTHON command within Statistics syntax files. It is not possible to guarantee that mechanically converted code will be correct due to the dynamic type nature of Python and a few other issues, but I have created an extension command, STATS CONVERT PYTHON that will produce syntactically correct Python 3 code from .py or .sps files. For BEGIN PROGRAM blocks, it extracts the Python 2 code, converts it, and puts it back with an updated BEGIN PROGRAM command. It handles either single files or wildcard-specified batches of code. It has a dialog box and syntax, and the syntax supports F1 help. The actual changes to the Python code are done using a library that is part of the Python 3 distribution.
This extension is now posted to the Extension Hub, so you can get it via the Extensions > Extension Hub menu in Statistics. Since it was written using Python 3.8, it is marked as requiring
As part of my testing of this extension, I took all of the example code from the Programming and Data Management book, which still is in Python 2, and converted it (can be done with just one use of the dialog box). There are 121 code files in those examples, some of which don't actually include any Python code, because the book also covers other topics. Only two failed conversion: one was actually syntactically invalid Python 2 code, and the other had a very weird XML xpath expression in a literal.