2

I'm trying to use a Python plugins in Apama. Unfortunately I always get the following error message when starting the correlator.

Failed to initialize correlator: Could not initialise the Python plugin. Set AP_PYTHONHOME to the location of python

If I test it locally, the application will work fine. But as soon as I switch to the production system and try to call the Python application via the .mon file this error occurs.

Can anyone tell me why it can't initialize Python?

Apama is configured and started using the following command.

/correlator --config /opt/apama-rules/deploy --applicationLogLevel DEBUG -l /usr/apama/properties/apama/license/icense.xml
2019-01-31 13:39:27.479 ##### [140402990063488] - There are 2 CPU(s)
2019-01-31 13:39:27.479 ##### [140402990063488] - Correlator command line: ./correlator --config /opt/apama-rules/deploy --applicationLogLevel DEBUG -l /usr/apama/properties/apama/license/ApamaServerLicense.xml
2019-01-31 13:39:27.479 ##### [140402990063488] - Current Working Directory: /opt/Apama/bin
2019-01-31 13:39:27.479 ##### [140402990063488] - PATH: /opt/Apama/bin:/jre/bin:/bin:/jre/../bin:/sbin:/usr/sbin:/bin:/usr/bin
2019-01-31 13:39:27.479 ##### [140402990063488] - LD_LIBRARY_PATH: /opt/apama-rules/deploy/lib:/apamawork_10.3/lib:/opt/Apama/lib:/jre/lib/amd64/server:/jre/lib/amd64
2019-01-31 13:39:27.480 ##### [140402990063488] - Current UTC time: 2019-01-31 12:39:27, local timezone: TZ not set so using system default
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - port                     = 15903
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - output queue size        = 10000
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - output queue batch size  = 100
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - output queue mode        = blocking
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - environment variable     = APAMA_PLATFORM=amd64-rhel7
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - environment variable     = AP_PYTHONHOME=/opt/Apama/third_party/python/lib/python3.6/site-packages
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - environment variable     = APAMA_LIBRARY_VERSION=10.3
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - environment variable     = APAMA_JRE=/jre
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - environment variable     = APAMA_ENVSET=10.3:/opt/Apama:amd64-rhel7
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - environment variable     = APAMA_WORK=/apamawork_10.3
2019-01-31 13:39:27.480 ##### [140402990063488] - Input value - environment variable     = APAMA_HOME=/opt/Apama
2019-01-31 13:39:27.480 ##### [140402990063488] - Using memory allocator                 = TBB scalable allocator
[...]
2019-01-31 13:39:27.717 ERROR [140402990063488] - Failed to initialize correlator: Could not initialise the Python plugin. Set AP_PYTHONHOME to the location of python
Raduan Santos
  • 1,023
  • 1
  • 21
  • 45
Hack
  • 83
  • 6

5 Answers5

3

For the correlator to find the python library to load, the environment variable AP_PYTHONHOME should be set to the location of python not to the location of the python site-packages. Try setting AP_PYTHONHOME to /opt/Apama/third_party/python (assuming that is where your python is actually installed). I'll note that it is useful to have the python site-packages on your PYTHONPATH.

  • Thanks for your replay. I have change it to /opt/Apama/third_party/python but I getting the same error. – Hack Feb 01 '19 at 07:13
  • @Hack : Can you describe how you are starting the correlator in this case? The correlator should be started from a command prompt where the Apama/bin/apama_env file has been sourced (**source /opt/Apama/bin/apama_env**) and that environment should not be setting the AP_PYTHONHOME variable when you are using the install. I'll note that it is not recommended to be running the correlator from the install's bin directory as that will potentially pollute the install with run-time files. – Dan Fournier Feb 01 '19 at 12:59
  • @Hack : I see your further reply that you have fallen victim to python vs. python3. When in the Apama environment on linux, use python3 to invoke the python interpreter and it will execute the python3 interpreter included with Apama under the $APAMA_HOME/third_party/python directory. See [https://www.python.org/dev/peps/pep-0394/](https://www.python.org/dev/peps/pep-0394/) – Dan Fournier Feb 01 '19 at 13:38
2

There have been some other good answers (it won't let me add a comment) - but I'll note that if you have a full installation (community or otherwise) or a docker image, then you shouldn't need to set AP_PYTHONHOME at all. When Python is located within the Apama installation it will be located automatically.

If you are using a core installation, then you will need to provide your own Python installation and point AP_PYTHONHOME to it. Documentation for that can be found in this blog post: http://www.apamacommunity.com/using-python-plug-ins-with-the-apama-core-installation/

  • Thanks for your replay. Ok I found out that the environment variables are loaded when starting the service. The following will be done: PYTHONPATH="$PYTHONPATH:$APAMA_HOME/third_party/python/lib/python3.6/site-packages" [...] epxort PYTHONPATH [...] print: :/opt/softwareag/Apama/third_party/python/lib/python3.6/site-packages Looks like the shell script isn't allowed to call the environment variables? – Hack Feb 01 '19 at 09:05
  • Hmm, sorry I missed your follow-up question. I'm not 100% sure exactly what your problem is here. Note we were talking about AP_PYTHONHOME and not PYTHONPATH. One thing you don't give is how you installed Apama. Also: are you running inside an Apama Command Prompt (having run source Apama/bin/apama_env) – Matt Johnson Feb 14 '19 at 16:16
1

Ensure you export the env variable AP_PYTHONHOME=/path of python/. An example,

export AP_PYTHONHOME=/usr/local/python/3.6.6

should be set in your bash profile. AP_PYTHONHOME is the parent directory given via --prefix option during python installation.

Venki
  • 11
  • 2
1

Looking at the environment variables, you have: AP_PYTHONHOME=/opt/Apama/third_party/python/lib/python3.6/site-packages

I'd be surprised if that's the correct directory: I think you want AP_PYTHONHOME=/opt/Apama/third_party/python

HenryLockwood
  • 215
  • 1
  • 8
1

Ok the problem was that the python default version linked to 2.7 I changed the version to version 3. alias python='/usr/bin/python3'.

Hack
  • 83
  • 6