【发布时间】:2018-03-27 10:11:32
【问题描述】:
我从 bash 运行这个命令(在我的例子中是 zsh)
python images/classify_image.py --image_file images/new_name.jpg
我得到了正确的输出:
power drill (score = 0.97464)
hand blower, blow dryer, blow drier, hair dryer, hair drier (score = 0.00101)
carpenter's kit, tool kit (score = 0.00043)
screwdriver (score = 0.00034)
joystick (score = 0.00028)
但是当我尝试在我的 laravel 项目中重现相同的东西时,我遇到了一个错误。我的控制器内的代码是这样的:
$process = new Process('python images/classify_image.py --image_file images/new_name.jpg');
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
dd($process->getOutput());
我正在使用 Composer - Process class 来执行 Laravel 内置的命令。运行此代码后,我收到此错误:
命令“python images/classify_image.py --image_file images/new_name.jpg”失败。退出代码:1(一般错误)工作目录:/var/www/html/share/public 输出:================ 错误输出:======== ======== Traceback(最近一次调用最后一次):文件“images/classify_image.py”,第 46 行,在 import tensorflow as tf ImportError: No module named tensorflow
有人可以给我提示,为什么我会收到这个错误? Laravel 似乎无法访问 TensorFlow,但是为什么我能够从不在 Laravel 项目中的 shell 执行此命令?
【问题讨论】:
-
TensorFlow 通常安装在某种封闭环境中,您的普通用户可以访问该环境 - 但 php 不会。我不知道是不是这样,但这是最有可能的问题。
-
@JoelHinz,可能就是这样,但我可以解决它吗?
标签: php python laravel shell tensorflow