如果我在python脚本中导入theano,shell_exec将返回NULL


shell_exec returns NULL if I import theano in python script

我在php中使用shell_exec()来执行python脚本。然而,当我在脚本中导入自己的模块时,shell_exec()返回NULL,这是python脚本:

import theano
import sys
video_file_name = sys.argv[1]
print video_file_name

但当我不导入theano时,shell_exec()工作得很好。这是我的shell_exec()代码:

$output = array();
$command = escapeshellcmd('python test.py Videos');
$output = shell_exec($command);
var_dump($output);

是不是因为导入teano需要很长时间,shell_exec()有一些限制,所以不能等待那么长时间?

我解决了这个问题,这与theano无关,实际上是apache的权限问题,和往常一样。以下是我解决问题的方法,以防这对某人有所帮助。在您的python scirpt:中尝试此代码

try:
    import theano
except Exception as e:
    print('Failed to open file: %s' % (e,))

然后我发现它抛出了一个权限错误,在我使用chmod更改权限后,一切都很好。