Python脚本不是从本地的PHP脚本执行的

2024-10-02 20:36:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用PHP和XAMPP。我已经启用了端口localhost:8080,我想从我的PHP脚本(index.php)执行一个python脚本(Main.py)。我的PHP脚本位于:

/Users/User/.bitnami/stackman/machines/xampp/volumes/root/htdocs/index.php

Python脚本位于:

/Users/User/.bitnami/stackman/machines/xampp/volumes/root/htdocs/Main.py。在

我的Python脚本如下:

print('Hello World')

我的PHP脚本如下:

^{pr2}$

(/usr/local/bin/python3which python3在终端的输出)

但是,我在localhost:8080得到的输出是:

string(40) "sh: 1: /usr/local/bin/python3: not found"

我还用exec()测试了我的行的不同变体,例如写了exec('/Users/User/.bitnami/stackman/machines/xampp/volumes/root/htdocs/Main.py ' . ' 2>&1'),但是没有返回正确的输出。在

我做错了什么?我该怎么解决?

我知道在StackOverflow(Running a Python script from PHPCan't execute Python script from PHP documentPython Script Failing to Execute from PHP exec()How to properly call Python 3 script from PHP?)上也有类似的帖子,但这些文章对我来说都不起作用。在

我想知道我的问题是否与我没有进行任何配置来在XAMPP上运行Python脚本有关,正如这里的一些文章(Running Python scripts with Xampp)中所描述的那样。在


Tags: frompy脚本mainrootuserspython3php