Introduction to Python Scripts
The Scripting Facility for IBM® SPSS® Statistics provides the ability to create Python ® scripts that operate on the IBM SPSS Statistics user interface, manipulate output objects, and run command syntax. This feature requires the IBM SPSS Statistics - Integration Plug-in for Python, which is installed by default with your IBM SPSS Statistics product..
A companion interface is available for creating Python programs that enable you to control the flow of command syntax jobs, read and write data, and create custom procedures. See the topic Introduction to Python Programs for more information.
Scope
You can run Python scripts directly from within IBM SPSS Statistics, from within Python programs, or from an external Python process, such as a Python IDE or the Python interpreter.
Python Script Run from IBM SPSS Statistics. You can run a Python script from Utilities>Run Script or from the Python script editor which is launched when opening a Python file (.py) from File>Open>Script. Scripts run from the Python editor that is launched from IBM SPSS Statistics operate on the IBM SPSS Statistics client that launched the editor. This allows you to debug your Python code from a Python editor.
Python Script Run from an External Python Process. You can run a Python script from any external Python process, such as a Python IDE that is not launched from IBM SPSS Statistics, or the Python interpreter. The script will attempt to connect to an existing IBM SPSS Statistics client. If more than one client is found, a connection is made to the most recently launched one. If an existing client is not found, the Python script starts up a new instance of the IBM SPSS Statistics client. By default, the Data Editor and Viewer are invisible for the new client. You can choose to make them visible or work in invisible mode with datasets and output documents.
- Mac. To run a Python script from an external Python process on Mac, launch the Programmability External Python Process application, installed with IBM SPSS Statistics - Essentials for Python and located in the directory where IBM SPSS Statistics is installed. The application launches IDLE (the default IDE provided with Python) and sets environment variables necessary for driving IBM SPSS Statistics.
Python Script Run from Python Program. You can run a Python script from a Python program by importing the Python module containing the script and calling the function in the module that implements the script. You can also call Python script methods directly from within a Python program. See the topic Running Python Scripts from Python Programs for more information.
- This feature is not available when running a Python program from an external Python process or when running a Python program from the IBM SPSS Statistics Batch Facility (available with IBM SPSS Statistics Server).
- When running Python scripting code from a Python program in distributed mode, you may need to configure your firewall to allow access from the remote server to which you are connected.
Limitations
- The interfaces exposed by the spss module (the module used for Python programs) cannot be used in a Python script.
- Calling methods in the SpssClient module with keyword arguments--in other words, keyword = value--is not supported.
Help
General information on the Scripting Facility for IBM SPSS Statistics and additional information on Python scripts is available from Scripting with the Python Programming Language .