0

I try to use the php running the python:

<?php 


$command=shell_exec('sudo python /var/www/html/FacialRecognition/simpleCamTest.py 2>&1');

echo $command;

?>

But the result show in chrome:

Unable to init server: Could not connect: Connection refused (frame:2143): Gtk-WARNING **: cannot open display:

I try any method to fix, but still not work.

Thank you.

0

You are running the python script in a shell. The warning do you get there is mostly from a missing environment variable DISPLAY=:0 by default. You should first try to run the python script from the commandline. Execute this command:

rpi ~$ sudo /usr/bin/python /var/www/html/FacialRecognition/simpleCamTest.py

Maybe you have to use another display number. If the script runs from the commandline you can look with echo $DISPLAY on the commandline what's the number of the display. Then you can try to execute the script from php with:

$command=shell_exec("/usr/bin/sudo /bin/bash -c 'DISPLAY=:0 /usr/bin/python /var/www/html/FacialRecognition/simpleCamTest.py 2>&1'")
  • I tried and show other error: No protocol specified Unable to init server: Could not connect: Connection refused (frame:6402): Gtk-WARNING **: cannot open display: :0 – Tony Lai Dec 26 '18 at 2:48
  • I have updated my answer. Have you checked if the script runs from the commandline? – Ingo Dec 26 '18 at 3:08
  • No protocol specified Unable to init server: Could not connect: Connection refused (frame:6790): Gtk-WARNING **: cannot open display: :0.0 I try to command line to run still show the error – Tony Lai Dec 26 '18 at 3:15
  • I saw other comment, because i installed xrdp for remote from my PC, the problem related to this? – Tony Lai Dec 26 '18 at 3:18
  • I don't know anything about your python program. It seems it needs a graphical user interface. What operating system do you use? Is it Raspbian Stretch Lite? It is not a problem of php. You must get the script to run from the command line first. How do you start the script? Local with a connected monitor and keyboard, or within a window of a rdp/vnc remote desktop connection? Best for first testing is a local login. – Ingo Dec 26 '18 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.