普通网友 2016-07-26 11:53
浏览 419
已采纳

PHP exec命令运行python脚本但不运行python3

I currently have python 2.7 installed as part of OSX, and recently installed 3.5.2.

I'm running a local webserver on my mac using XAMPP, and when I execute the python script from within apache, it loads fine:

$executePython = "python " . __DIR__ . "/cycle/cutoff.py $device_id $processPreviousMinutes";
exec("$executePython");

However, when I replace python with python3 my script refuses to run. I can invoke it manually from the command line using both versions, however it seems like the apache account/daemon doesn't have access to python3. Would this be something to do with a configuration file that I've overlooked?

  • 写回答

1条回答 默认 最新

  • dou8mwz5079 2016-07-27 10:51
    关注

    We don't want to mess up with the system wide path on the latest OSX. What if you add the python3 path in your script like this and then do your normal stuff

    putenv("PATH=/usr/local/bin/:" . exec('echo $PATH'));
    $executePython = "python3 " . __DIR__ . "/cycle/cutoff.py $device_id $processPreviousMinutes";
    exec("$executePython");
    

    putenv just adds your python3 path to the whatever current path is in your XAMPP's apache.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系