1

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.

9
  • 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
    CommentedJan 19, 2019 at 7:33
  • And you tried this via sudo from console?CommentedJan 19, 2019 at 7:34
  • 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
    CommentedJan 19, 2019 at 7:36
  • It might be an environment problem not having set some variables. Did you try to start python wrapped into bash -c?CommentedJan 19, 2019 at 7:41
  • 1
    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.CommentedJan 19, 2019 at 10:56

1 Answer 1

1

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

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.