1
votes

I am executing python script from php which is importing webdriver from selenium but I am getting error

Traceback (most recent call last): File "/var/www/html/spreadsheet/script.py", line 10, in from selenium import webdriver ImportError: No module named selenium

Selenium is installed and python script is working perfectly from bash. i have also run it from sudo but still getting the same error.

my php script is

$dir = __DIR__;
$command = "sudo -u www-data python ".$dir."/script.py 2>&1";

$pid = popen( $command,"r");

while( !feof( $pid ) )
{
 echo fread($pid, 256);
 flush();
 ob_flush();
 usleep(200000);
}
pclose($pid);

and in script.py i am getting eror

from selenium import webdriver
import time
import os
import os.path

so i am getting error while importing webdriver.

1
i am using ubuntu and i have added www-data ALL=(ALL) NOPASSWD:ALL in /etc/sudoers to give sudo access to php.You can remove sudo -u www-data and try running with python ".$dir."/script.py 2>&1 only - Hassaan
And you tried this via sudo from console? - Quasimodo's clone
yes script is fine, i already mentioned in question. with sudo and without sudo its fine form console but from php it is throwing error for module not found - Hassaan
It might be an environment problem not having set some variables. Did you try to start python wrapped into bash -c? - Quasimodo's clone
You should anwer your own question describing all the analysis and steps you have done and accept this. So other people looking for such an issue could get a solution. StackOverflow is meant to be a knowledge database. - Quasimodo's clone

1 Answers

1
votes

Is the selenium module installed? if not installed it using pip install selenium --> for Python 2.7 and above pip3 install selenium --> for Python3.^ and above