0

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.

Keshav Chawla
  • 13
  • 1
  • 4
  • yes, it can be a path or a permission problem or any other problem. The reason why you get no answer is because you give way to less information. –  Jun 08 '20 at 19:13
  • @MaxMuster added more detail to clarify the exact issue. – Keshav Chawla Jun 08 '20 at 19:33
  • show us scriptname.py around line 46 –  Jun 09 '20 at 03:42
  • where is the folder `uploads` relative to the script ? –  Jun 09 '20 at 03:44
  • Apache runs under a certain user, which has it's own environment, permissions, rights, ... So you have proven that the script works by running it with your user, but it does not prove the apache user can do the same. – Nic3500 Jun 09 '20 at 04:40

1 Answers1

0

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.

Keshav Chawla
  • 13
  • 1
  • 4