Hi all,

Many thanks for the suggestions to put the declaration of the environment variable PYTHONPATH in a BEGIN block before Inline is called.

That did the trick of getting the Perl code to find the Python code to execute.

I then found two other issues to solve, the first involving the Perl namespace of my codebase, and the second a small requirement of the Python module httpie.

I'll detail these 2 issues in case others also encounter them.

1) If the Python code is embedded and called from within a Perl package in a namespace one may get the error message when running the Perl code that the Python method is 'not found' even though the Python module itself was found and entered.


It appears that the Inline modules sets up the Python class that is imported, as a Perl package to be part of the Perl namespace located at the Inline API hash given by the API key 'pkg'.

As an example, my original code snippet is:

package X::Y::Z::Core;

... other use statements and comments...

use Inline::Files;
use Inline (Python => 'file', directory => '/tmp/_Inline');
use Inline::Python;

... lots of other Perl statements

my $pyobj = new VSO_WS;
$pyobj->{'dbquery'} = $block;
$query = $pyobj->get_data();

... more processing statements

1;

____PYTHON__

from VSO import VSO_WS


The key line is in BOLD.

After adding the BEGIN block to declare PYTHONPATH before Inline is initialized, the error message I got when executing the above code snippet was that the Python method get_data was 'not found'.

The solution was to fully qualify the Perl namespace path to VSO_WS so that the address used in the Inline code would work correctly when called from Perl.

Changing the line in BOLD above to:

my $pyobj = new X::Y::Z::Core::VSO_WS;

worked!

No error messages about  get_data, and data is indeed returned from Python to Perl as needed.

2) The Python module httpie, when executed from a codebase as Apache, will need a directory .httpie to be created initially beforehand. Once directory .httpie is created, the python code using http to do a GET operation on a remote Python web service will then be executed. NOTE: The initially empty directory .httpie should be owned by Apache.


Thanks again for all the very helpful replies,

--Ed

Reply via email to