SPSS Statistics

Python 2 to Python 3 Conversion for SPSS Statistics Version 27 

Wed January 20, 2021 03:42 PM

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 not yet posted to the Extension Hub, but you can get it from my OneDrive site here.

https://1drv.ms/u/s!AoWcE61g_FAdisIcF4kHvYQTy88cgw?e=kVAgk3

Download STATS_CONVERT_PYTHON.spe and install it using Extensions > Install Local Extension Bundle. Of course, it does require Python 3.

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.  

Let me know of any issues encountered. I hope to get this posted to the Extension Hub soon.

Statistics

0 Favorited
5 Views
0 Files
0 Shares
0 Downloads