#1 Le 06/05/2008, à 19:40
- guibsou
executer fichier python depuis une page web
Bonjour
le titre est assez explicite.
je cherche à executer un petit script python de matplotlib à partir d'une page web.
voici le script:
#!/usr/bin/python
from __future__ import division
from pylab import *
Z = [[1,2,3,4],[2,5,7,3],[8,6,7,1][2,5,4,0]]
ax = subplot(111)
im = imshow(Z, cmap=cm.jet, extent=(0,800,800,0))
axis('off')
im.set_interpolation('bilinear')
c = contourf(Z)
savefig('map')
#show()
j'ai rajouté dans le sudoers (via nano /etc/sudoers et non pas en faisant visudo (me dire si c'est grave)) cela :
www-data ALL=NOPASSWD: ALL
mon script est appellé par la commande php suivante:
system("python /var/www/python/script_matplot.py");
j'ai bien fait les chmod +x, chmod 777, et chown www-data pour le fichier script_matplot.py
alors j'arrive bien à executer en ligne de commande ce script que ce soit en root, ou en www-data, par contre, je n'arrive pas à l'executer depuis la page php.
j'ai systematiquement ce message de retour dans les log d'erreurs d'apache:
/var/lib/python-support/python2.5/gtk-2.0/gtk/__init__.py:72: GtkWarning: could not open display
warnings.warn(str(e), _gtk.Warning)
/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py:40: GtkWarning: gdk_cursor_new_for_display: assertion `GDK_IS_DISPLAY (display)' failed
cursors.MOVE : gdk.Cursor(gdk.FLEUR),
Traceback (most recent call last):
File "/var/www/python/script_matplot.py", line 4, in <module>
from pylab import *
File "/usr/lib/python2.5/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/usr/lib/python2.5/site-packages/matplotlib/pylab.py", line 292, in <module>
from matplotlib.pyplot import *
File "/usr/lib/python2.5/site-packages/matplotlib/pyplot.py", line 37, in <module>
new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/usr/lib/python2.5/site-packages/matplotlib/backends/__init__.py", line 24, in pylab_setup
globals(),locals(),[backend_name])
File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py", line 40, in <module>
cursors.MOVE : gdk.Cursor(gdk.FLEUR),
RuntimeError: could not create GdkCursor object
Voila.
apparement, il y a une erreur avec le display. seulement, le script ne fait que produire une image et la sauvegarde sans rien afficher à l'ecran. Dois-je rajouter un packet ?
si quelqu'un peut m'eclaircir sur ce que je dois faire afin de pouvoir executer ce script via une action d'une page web.
Merci
Hors ligne
#2 Le 06/05/2008, à 20:04
- geenux
Re : executer fichier python depuis une page web
En faisant
apt-cache search apache python
on trouve 2 paquets suceptibles de t'intéresser:
libapache2-mod-python - Apache 2 module that embeds Python within the server
libapache2-mod-python-doc - Apache 2 module that embeds Python within the server
Hors ligne
#3 Le 07/05/2008, à 09:20
- guibsou
Re : executer fichier python depuis une page web
Merci geenux
le probleme ne venait pas d'une librairie manquante
la solution est de rajouter en debut de script
import matplotlib
matplotlib.use('Agg')
#*before* importing pylab, in case the default matplotlibrc setting has
#a GUI backend (eg 'backend : GTKAgg')
Hors ligne