AtomCoder's avatar

Laravel Python - How to import modules?

Hi Guys,

Im running a test python script inside laravel like so:

public function handle()
{
      $process = new Process(['python','app/Python/test.py']);
      $process->run();

      if (!$process->isSuccessful()) {
          throw new ProcessFailedException($process);
      }

      \Log::info( $process->getOutput() );
}

The problem is when I import a python module (in test.py) I get an error:

Error Output:
================
Traceback (most recent call last):
  File "app/Python/test.py", line 1, in <module>
    import requests
ImportError: No module named requests
 {"exception":"[object] (Symfony\Component\Process\Exception\ProcessFailedException(code: 0): The command \"'python' 'app/Python/test.py'\" failed.

Obviously the module is missing. How can I install and import modules within the laravel enviroment?

0 likes
1 reply
Talinon's avatar

@atomcoder Looks to be purely a python related error. Have you installed the requests python module?

Please or to participate in this conversation.