develooper Front page | perl.inline | Postings from July 2018

Inline::Python and PYTHONPATH

Thread Next
July 20, 2018 16:16
Inline::Python and PYTHONPATH
Message ID:
Hi all,

I have a Python class and methods that I want to call from Perl.

My test script works fine, executed as me. The _Inline directory is created and the Python module is imported and calls to the Python methods from Perl work as expected.

The Python module itself is in another directory which is listed in the PYTHONPATH shell environment variable. It would seem that the Python interpreter indeed uses PYTHONPATH to find the location of the module, when the parent script is executed as myself.

When I place the same Perl code in the codebase that it will execute in, run by Apache, the method py_eval, called from the load method in Inline::Python, fails to find the python module.  Adding a declaration of PYTHONPATH in the Perl code to include the directory where the python module is located did no good.

I did have to specify the directory where _Inline should be located, and I made that owned by Apache (www). That part worked.

Here is a snippet of the Perl code:

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 = VSO_WS->new();
    $pyobj->{'dbquery'} = $block;
    $query = $pyobj->get_data();

... more processing statements


from VSO import VSO_WS

Here is the error I see in the Apache log file:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
ImportError: No module named VSO
Error -- py_eval raised an exception at /Library/Perl/5.8.6/darwin-thread-multi-2level/Inline/ line 221.

I could place all the Python code in the __PYTHON__ section, but I would prefer to keep it in a separate module 

Any ideas on getting the Python interpreter to find my Python module would be greatly appreciated.



Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About