[英]sh: 1: python: not found when execute python script from php
I'm tring to execute a python script call from php with the command below:我正在尝试使用以下命令从 php 执行 python 脚本调用:
$output = shell_exec('python /var/www/html/sna/server/userManagement.py '. $user.' '. $pass .' \''.$action.'\' 2>&1');
But when I execute it I get this但是当我执行它时,我得到了这个
sh: 1: python: not found
But python is correctly installed in my env.但是python已正确安装在我的环境中。
If I digit如果我数
type -a python
I get the path of python in this env like below (not sure because they are two)我在这个环境中得到了 python 的路径,如下所示(不确定,因为它们是两个)
python is /home/leonardo/miniconda2/bin/python
python is /home/leonardo/miniconda2/envs/sna/bin/python
At the very beginning of the python script I have include在 python 脚本的最开始,我包括
#! /usr/bin/env python
But I recieve always the same error.但我总是收到同样的错误。 How can I solve ?
我该如何解决?
EDIT编辑
I tried to add python path to the $PATH
with command我尝试使用命令将 python 路径添加到
$PATH
export $PATH:/home/leonardo/miniconda2/envs/sna/bin/python
But I get the same error anywhay但无论如何我都会遇到同样的错误
Your binary is not in the PATH for the webservers user account.您的二进制文件不在 webservers 用户帐户的 PATH 中。
PHP inherits the PATH from Apache. PHP 从 Apache 继承了 PATH。 And most distros set a fairly restrained:
大多数发行版设置了一个相当克制的:
SetEnv PATH /bin:/usr/bin
Either change that, or putenv()
in PHP, or use absolute paths instead.要么更改它,要么在 PHP 中使用
putenv()
,或者改用绝对路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.