简体   繁体   中英

Running a python script on server - works through command line but not through browser as user apache

Specifically getting this error:

WARNING: Cannot find unidecode lib. Expect issues with index sorting
lstat(./kpsewhich) failed: ./kpsewhich: No such file or directory
kpathsea: Can't get directory of program name: ./kpsewhich
Traceback (most recent call last):
  File “scriptname.py”, line 46, in 
    doc = TeX(myfile=outputname).parse()
  File "/usr/local/lib/python3.6/site-packages/plasTeX/TeX.py", line 136, in __init__
    fname = self.kpsewhich(myfile)
  File "/usr/local/lib/python3.6/site-packages/plasTeX/TeX.py", line 1380, in kpsewhich
    raise OSError('Could not find any file named: %s' % name)
OSError: Could not find any file named: uploads/filename

I have a python script that's intended to convert some files which I am running with PHP form on an apache server. When I run the python script directly through the command line I am able to get a successful output (a separate file is produced) however when I run it through the browser I am getting the above error.

I have checked to confirm that pypandoc has been imported along with the other modules for the python script.

I call the python script using (in callscript.php)

shell_exec("/usr/bin/python3 scriptname.py $target_file 2>&1; echo $?");

and specifically, this line is giving me the error within scriptname.py:

TeX(myfile=outputname).parse()

I should note that outputname is the same name as the file I am trying to convert. Thanks for the help.

A colleague was able to solve the issue. It turns out that PHP resets the PATH variable so instead of running it as

shell_exec("/usr/bin/python3 scriptname.py $target_file 2>&1; echo $?");

I ran it as

shell_exec("PATH=/usr/bin python3 scriptname.py $target_file 2>&1; echo $?");

and it worked. Thanks for all that helped.

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