【发布时间】:2020-10-26 10:14:13
【问题描述】:
我有以下文件可以使用 perl 中的 python API AnimalsWrapper.py:
import os
class AnimalsWrapper():
def __init__(self):
self.name = 'dog '
def getName(self):
os.environ['HELLO'] = 'test'
return self.name + '\n'
AnimalsWrapper.pm:
package AnimalsWrapper;
use parent qw(PythonBase);
package main;
use Inline Python;
our %ENV;
1;
PythonBase.pm
package PythonBase;
use Inline Python => <<"END";
import sys
sys.path.append('<pkgpath>/python3/3.6.3a/bin/python3')
sys.path.append('<pkgpath>/python3/3.6.3a/lib/python3.6/site-packages/')
END
1;
这是我用来调用 python API 的 perl 脚本。
#!/usr/bin/perl
use strict;
use warnings;
use lib '<path to the above python code>';
use AnimalsWrapper;
our %ENV;
my $obj = AnimalsWrapper->new();
print $obj->getName();
print $ENV{HELLO}; ==> here this says its uninitalized.
通过这种方式没有 IPC,并且从 perl 调用 python API 时,它的进程相同,但环境变量仍然不可用。感谢您提供任何帮助或建议。
【问题讨论】: