简体   繁体   中英

Laravel - Python script execution

I have to execute a Python script which pulls a large amount of data to the database. It is working fine while I am running a project using the command php artisan serve , but it is throwing an error after calling the public folder URL given below

localhost/project/public

Error:

The command "python /opt/lampp/htdocs/laravel/projectname/beta/projectname/public/python/pubmed_abstract/pubmed_engine.py '{"term":"cancer"}'" failed.

Exit Code: 1(General error) Working directory: /opt/lampp/htdocs/laravel/infocytosis/beta/infocytosis/public Output:

================ Error Output: ================

Traceback (most recent call last): File "/opt/lampp/htdocs/laravel/projectname/beta/projectname/public/python/pubmed_abstract/pubmed_engine.py", line 5, in from Bio import Entrez ImportError: No module named Bio

Code I used:

   $python_path=public_path().'/python/doom_abstract/doom_engine.py';
   
   $variables='{"term":"'.addslashes($request->term).'"}';

   $process = new Process("python $python_path '$variables'");
   $process->run(); 

  return redirect()->back()->withMessage('Filter saved successfully');

您可以尝试以下一个

$python_path=public_path('python/doom_abstract/doom_engine.py');

Instead of:

$process = new Process("python $python_path '$variables'");
$process->run(); 

how about

shell_exec("python $python_path '$variables'")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM