1

我在 python pyheif 库中发现了一个奇怪的错误。我正在尝试在 php 函数 exec('python command', $output); 中运行外部 python 代码 我可以使用 exec() 的第二个参数 $output 在数组中获取 python 消息。

蟒蛇代码(test.py):

# -*- coding: utf-8 -*-
import sys
import os
import base64
from PIL import Image # pip3 install pillow
import pyheif  # pip3 install pyheif
import io
print("hello world!")

php代码(test.php):

<?php
exec("python3 test.py", $output);
var_dump($output);

这在命令行上运行良好,但在 Web 浏览器上运行良好。但是,当我删除 import hyheif 行或将 print('hello world') 移到 hyheif 行之前时,它适用于 cli 和 Web 浏览器。我得到了结果:你好世界字符串。

我一点头绪都没有。hyheic 库是否会在 Web 浏览器上导致此问题,而它在命令行上运行良好?

我需要导入 hyheic 库以在浏览器上将 heic 转换为 jpeg。我的问题是我无法从 python 代码中获取 php 的结果。

当我导入 hyheif 库时,我得到以下结果:

shell:/var/www/myfolder$ php test.php
array(1) {
  [0]=>
  string(12) "hello world!"
}

在我的 chrome 浏览器上:

array(0){}
4

0 回答 0