0

I need a php script to execute a python script. Now the python code looks like this:

test.py

import sys
try:
    import numpy
    print 'Numpy was loaded'
except:
    print 'Could not Load Numpy'

All the following commands print 'Numpy was loaded':

$python test.py
$python2.7 test.py

PHP Script:

exec('python test.py',$output,$ret);
var_dump($output);

The PHP script works if the line 'import numpy' is removed.

I have tried the following things:

  1. Use absolute path in php script : exec("/usr/bin/python /home/pg/test.py"), exec("python2.7 test.py")
  2. Added absolute path of pwd and numpy using sys.path.append("path/to/numpy/dir where init.py is present")

It can be a user permission issue as well, but I have no idea.

EDIT

The exact error that python gives is :

"from numpy.linalg import lapack_lite"
  ImportError: /opt/lampp/lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /lib/libgfortran.so.3
Pranjal
  • 796
  • 1
  • 8
  • 24

0 Answers0