Tengo un problema al ejecutar una secuencia de comandos de Python desde una secuencia de comandos PHP. Mi cliente usa Bluehost, entonces instalé un módulo de terceros (numpy) para Python con el método easy_install descrito aquí: https://my.bluehost.com/cgi/help/530?step=530La secuencia de comandos PHP no puede obtenerse desde la secuencia de comandos de Python
Para demostrar mi problema, he creado dos scripts de Python y un script de PHP.
hello.py contiene:
print "Hello, World!"
hello-numpy.py contiene:
import numpy
print "Hello, World!"
El script PHP contiene:
Output from exec('python hello.py'): <?php echo exec('python hello.py'); ?><br>
Output from exec('python hello-numpy.py'): <?php echo exec('python hello-numpy.py'); ?><br>
Output from exec('whoami'): <?php echo exec('whoami'); ?>
en cuando me siento esta salida de PHP:
Output from exec('python hello.py'): Hello, World!
Output from exec('python hello-numpy.py'):
Output from exec('whoami'): venicetw
Sin embargo, ejecutar estas secuencias de comandos de la ventana de SSH se obtienen los siguientes resultados:
# python hello.py
Hello, World!
# python hello-numpy.py
Hello, World!
# whoami
venicetw
Parece PHP no recibe ninguna salida cuando las importaciones de script Python numpy, pero funciona bien desde SSH. Además, PHP obtiene un estado de devolución de 0 para hello.py pero 1 para hello-numpy.py. Pensé que podría ser un problema de permisos, pero tanto PHP como SSH se ejecutan como el usuario "venicetw". ¿Qué evitaría que PHP y Apache obtengan el resultado de la secuencia de comandos de Python? ¿Es algo que puedo discutir con Bluehost, o algo más que debería verificar? Estamos usando Apache 2.2.21
, PHP 5.2.17
, Python 2.4.3
y numpy 1.6.0
.
Actualizar: grabados SSH las siguientes rutas de Python:
/home8/venicetw/public_html/venicenoise/python
/home8/venicetw/.local/lib/python2.4/site-packages/ogcserver-0.1.0-py2.4.egg
/home8/venicetw/.local/lib/python2.4/site-packages/PIL-1.1.7-py2.4-linux-x86_64.egg
/home8/venicetw/.local/lib/python2.4/site-packages/lxml-2.3.2-py2.4-linux-x86_64.egg
/home8/venicetw/.local/lib/python2.4/site-packages/WebOb-1.2b2-py2.4.egg
/home8/venicetw/.local/lib/python2.4/site-packages/PasteScript-1.7.5-py2.4.egg
/home8/venicetw/.local/lib/python2.4/site-packages/PasteDeploy-1.5.0-py2.4.egg
/home8/venicetw/.local/lib/python2.4/site-packages/Paste-1.7.5.1-py2.4.egg
/home8/venicetw/.local/lib/python2.4/site-packages/numpy-1.6.0-py2.4-linux-x86_64.egg
/home8/venicetw/.local/lib/python2.4/site-packages
/home8/venicetw/.local/lib/python/site-packages
/home8/venicetw/public_html/venicenoise/python
/usr/lib64/python24.zip
/usr/lib64/python2.4
/usr/lib64/python2.4/plat-linux2
/usr/lib64/python2.4/lib-tk
/usr/lib64/python2.4/lib-dynload
/usr/lib64/python2.4/site-packages
/usr/lib64/python2.4/site-packages/Numeric
/usr/lib64/python2.4/site-packages/PIL
/usr/lib64/python2.4/site-packages/gtk-2.0
/usr/lib/python2.4/site-packages
Pero Apache sólo imprime estos caminos Python:
/home8/venicetw/public_html/venicenoise/python
/usr/lib64/python24.zip
/usr/lib64/python2.4
/usr/lib64/python2.4/plat-linux2
/usr/lib64/python2.4/lib-tk
/usr/lib64/python2.4/lib-dynload
/usr/lib64/python2.4/site-packages
/usr/lib64/python2.4/site-packages/Numeric
/usr/lib64/python2.4/site-packages/PIL
/usr/lib64/python2.4/site-packages/gtk-2.0
/usr/lib/python2.4/site-packages
Solución: Al ejecutar/usr/bin/env de tanto PHP como SSH, pude determinar que PHP carecía de una variable de entorno para la ruta Python donde está instalado numpy. En este caso, agregando
putenv('PYTHONPATH=/home8/venicetw/.local/lib/python2.4/site-packages:/home8/venicetw/.local/lib/python/site-packages:');
al comienzo del script PHP, todo funciona como se esperaba.
Ah, tengo esto: "ImportError: No hay un módulo llamado numpy" Me pregunto si solo se trata de reiniciar Apache? –
Asegúrese de tener acceso a la misma versión de Python en ambas ocasiones. –
Acabo de verificar: ambos acceden a Python 2.4.3. Y al estar en un entorno de alojamiento compartido, reiniciar Apache no es una opción. –