要从 PHP 文件中调用 Python 文件,您需要使用 shell_exec 函数来调用它。
<?php $command = escapeshellcmd('/usr/custom/test.py'); $output = shell_exec($command); echo $output; ?>
这将调用脚本。但在顶部的脚本中,您还需要指定解释器。因此,在您的 py 文件中,在顶部添加以下行:
#!/usr/bin/env python
或者,您也可以在执行命令时提供解释器。
<?php $command = escapeshellcmd('python3 /usr/custom/test.py'); $output = shell_exec($command); echo $output; ?>
以上就是如何从PHP中调用Python文件?的详细内容,更多请关注php中文网其它相关文章!
已抢66297个
抢已抢36164个
抢已抢20030个
抢