普通网友 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.

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

报告相同问题?

悬赏问题

  • ¥15 WPF动态创建页面内容
  • ¥15 如何对TBSS的结果进行统计学的分析已完成置换检验,如何在最终的TBSS输出结果提取除具体值及如何做进一步相关性分析
  • ¥15 SQL数据库操作问题
  • ¥100 关于lm339比较电路出现的问题
  • ¥15 Matlab安装yalmip和cplex功能安装失败
  • ¥15 加装宝马安卓中控改变开机画面
  • ¥15 STK安装问题问问大家,这种情况应该怎么办
  • ¥15 关于罗技鼠标宏lua文件的问题
  • ¥15 halcon ocr mlp 识别问题
  • ¥15 已知曲线满足正余弦函数,根据其峰值,还原出整条曲线