在 php 代码中的 python 中导入 caffe

Import caffe in python in php code

我有一个test.php代码

$b = system("python test.py", $a);
echo $a;

和python test.py代码

import caffe
print('!')

当我通过控制台在服务器中使用 php test.php 时,可以并打印 !0。但是当我在浏览器中查看 test.php 时,它会出现一些错误并打印 1。但我不知道出了什么问题,因为 python 运行 通过系统函数。

我认为您的问题是基于权限:当您在控制台中 运行 test.php 时,此脚本是与您的用户一起执行的,但是当 运行 test.php 在网络浏览器,这个脚本是用网络服务器用户(可能是 www-data)执行的。

我建议使用更简单的py脚本:

print('!')

为了检查问题是否是由于许可而不是其他原因造成的。

您使用的是什么操作系统?