0

I am working on laravel and I must run a python script. I use these codes to run the script.

$process = new Process(['python', __ROOTPATH__.DIRECTORY_SEPARATOR.'pythonscripts'.DIRECTORY_SEPARATOR.'image-classification\train.py', '-p '.json_encode($parameters),'-m '.$parameters['trainingParameters']['model']]);

$process->run();

return $process->getOutput();

But I get an error as below:

Can't determine home directory

To solve this problem, I made some research. More clear one is this but it does not work for me.

#!C:\Users\monst\AppData\Local\Programs\Python\Python39\python.exe
os.environ['HOME'] = "C:/Users/monst/AppData/Local/Programs/Python/Python39"

I run xampp as administrator but it did not work as well.

If I run the script dirrectly, it works

Update 1


I debuged the python script step by step and I realized the error occurs at __import__('models.'+modelName) line. and modelName = 'lenet/vgg16/vgg19...'

models is a custom package at where the python script is

Update 2


Same codes work by php exec command.

Wtow
  • 98
  • 1
  • 8
  • whats the python command you want to run? – bhucho Dec 31 '21 at 14:18
  • @bhucho It includes tensorflow library and some custom libraries – Wtow Dec 31 '21 at 14:34
  • whatever you have written is question does not explain it completely so it hard to explain but I believe if you use Symfony process then you need to provide complete path of the file eg python /your/path/filemine.py – bhucho Dec 31 '21 at 14:56
  • @bhucho I provided excatly absolute path, I checked it. I can add the codes but it is so complex. I can summarize the codes like that: I get some parameters from outside, and with this parameters, I train a deep learning model. I debuged the codes step by step, and I realize that the error occures at __import__('models.'+modelName) python function. If I delete this line, I don't get any error. models is a package at same where python script is. And modelName = 'lenet/vgg16/vgg19...' – Wtow Dec 31 '21 at 17:14
  • I added some new experiement results to question. – Wtow Dec 31 '21 at 17:22
  • See some possible solutions here: https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path?rq=1 – miken32 Dec 31 '21 at 18:16
  • @miken32 Thanks for yor reply, I tried [this method](https://stackoverflow.com/a/67692/16394073) from your suggestion but I got same error at `spec.loader.exec_module(foo) ` line – Wtow Dec 31 '21 at 19:50
  • I don't think the problem is about importing method or python, I think it is about laravel but just it. I don't have any idea more than it. – Wtow Dec 31 '21 at 19:52

0 Answers0