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

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?

图片转代码服务由CSDN问答提供 功能建议

我目前安装了python 2.7作为OSX的一部分,最近安装了3.5.2。

我正在使用XAMPP在我的mac上运行本地网络服务器,当我从apache中执行python脚本时,它加载正常:

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

但是,当我替换 python with python3 我的脚本拒绝运行。 我可以使用两个版本从命令行手动调用它,但是似乎apache account / daemon无法访问python3。 这是否与我忽略的配置文件有关?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题