Python Integration with Pyro4
Panopticon can use Python for both data transforms and as a primary data source. The server part of Panopticon will send requests to Python, with data and/or Python code, via Pyro4 - Python Remote Objects. Pyro4 installs as a Python package in your Python environment, and connectivity is enabled by starting a Pyro process with a shell script file (.BAT script file) which is included in the Panopticon distribution zip-archive.
To set up a Python environment that can be used from Panopticon, follow these steps:
- Download and install Python.
- Install Pyro4.
- Install pandas.
- Install additional packages.
- Set the Pyro HMAC key.
- Start Pyro4.
Downloading and Installing Python
Download Python from https://www.python.org/downloads/ and select the release version you require as well as the right version for the operating system of your server. Note that Linux systems often have Python included out of the box. Install Python as described by documentation from Python.org. You can install Python on the same host that runs the Panopticon server, or a different host, if firewall settings and port mapping allow communication between the two hosts. If you are running Panopticon for development, testing or personal use on your workstation, install Python on your workstation as well.
Installing Pyro4
When Python is installed, add Pyro4 by installing it like a Python package. The Pyro4 version must be 4.71 or higher. On the command prompt, type python and press Enter to start a Python prompt. Then run this command:
pip install Pyro4>=4.71
Installing Pandas
When working with a data table in Python, the pandas package and the pandas DataFrame object provides many useful advantages and is highly recommended. Panopticon’s integration with Pyro4 will check if the object returned from Python is a pandas DataFrame and therefore the pandas package is required. On the Python prompt, run this command:
pip install pandas>=1.1.5
This will also automatically give you the NumPy package.
Installing Additional Packages
To be able to view and use the examples in the Panopticon example workbook “How to Python”, you are also required to install a few additional packages using these commands:
pip install scikit-learn>=1.1.3
pip install pyarrow>=10.0.0
Setting The Pyro HMAC Key
When you send a request to Pyro4, you are required to supply the correct password which is called the Pyro HMAC Key. This password protects the Python environment from unauthorized remote calls via Pyro4. You should create an environment variable named PYRO_HMAC_KEY on the host where Python and Pyro4 are installed. However, if PYRO_HMAC_KEY is not found or created, the environment variable will be created by the script used for starting Pyro4. The default value is password. You have the option of either:
- Creating the PYRO_HMAC_KEY and setting a password value of your choice
- Editing the start script and entering your password value instead of the default value password
When using Python from Panopticon, either as a transform or as a primary data source, you will supply the password as part of the connection settings in Panopticon. The password can also be saved in the Panopticon.properties file, by an Administrator, which will let Designer users create Python connections without knowledge of the password.
For details about the configuration of Python connectivity properties, see Properties: Panopticon.
Starting Pyro4
Before you can use Python from Panopticon, you must start the Pyro4 process that will receive requests from Panopticon and pass them on to Python. This is done by running a script included with Panopticon on the host where Python and Pyro4 are installed.
On Linux, you run the file start_Python_connectivity.sh which in turn runs the file pyro.py.
On Windows, you run the file start_Python_connectivity.bat which in turn runs the file pyro.py.
Multiple Python Environments on Windows
On Windows, you can install multiple Python versions in parallel, resulting in installation folders like the following examples:
- C:\Program Files\Python38
- C:\Program Files\Python39
- C:\Program Files\Python310
Each of these versions has their own package installations. For example, you can have one version of a package installed for Python 3.9 and another package version for Python 3.10.
NOTE: When installing packages for different versions of Python on a host which will serve multiple users, make sure you install from a command prompt with elevated privileges (run As Administrator), otherwise, packages will be installed under your own Windows user profile folder.
With Python for Windows downloaded from Python.org, you also get py.exe which is a Python launcher. When installing Python for all users, it is placed in C:\Windows\py.exe or C:\Users\<username>\AppData\Local\Programs\Python.
With the Python launcher py.exe, you can start a specific Python version as follows:
py -3.9
To make a package installation for a specific Python version, open a command prompt as Administrator and run:
py -3.9 -m pip install <packagename>
To start a Pyro4 process with a specific Python version (in this example, 3.9) you can launch Pyro4 as follows:
start_Python_connectivity.bat -3.9
(c) 2013-2024 Altair Engineering Inc. All Rights Reserved.