首页 > 解决方案 > 从 Symfony 进程执行 python 失败

问题描述

我正在执行一个简单python -v的:

$process = new Process(['python -v']);
$process->run();

try {
      if (!$process->isSuccessful()) 
      {
        throw new ProcessFailedException($process);
      }
     }
      catch (\Exception $e) {
            $this->logger->error($e->getMessage());
     }

但我得到了例外:

The command "'python -v'" failed.  Exit Code: 127(Command not found)  Working directory: /var/www/symfony/symfony/public  Output: ================   Error Output: ================ sh: 1: exec: python -v: not found

如果我从 shell 运行相同的命令,一切正常。

标签: phppythonlinuxsymfony

解决方案


改变

$process = new Process(['phyton -v']);

$process = new Process(['phyton',  '-v']);

参考。https://symfony.com/doc/current/components/process.html#usage


推荐阅读