Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhantomJS was placed in path and can execute in terminal, but PATH error in Python

note: PhantomJS runs in PyCharm environment, but not IDLE

I have successfully used PhantomJS in Python in the past, but I do not know what to do to revert to that set up.

I am receiving this error in Python (2.7.11): selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH.

I have tried to 'symlink' phantomjs to the path (usr/local/bin [which is also in the path]), and even manually locate /usr/local/bin to place phantomjs in the bin folder. However, there is still a path error in python.

What am I missing?

like image 438
Phillip Avatar asked Mar 13 '23 05:03

Phillip


2 Answers

I solved this by passing the executable_path keyword arg to the driver constructor. For example:

driver = webdriver.PhantomJS(executable_path="/Path/to/driver/phantomjs")

Note that this must be the driver file itself, not the folder which contains it.

Thanks to PhantomJS() not running in pyCharm for hinting at this solution.

like image 141
Code-Apprentice Avatar answered Mar 16 '23 04:03

Code-Apprentice


Download - http://phantomjs.org/download.html

/usr/bin is restricted on Mac, but putting /bin/phantomjs in /usr/local/bin works

like image 41
user2643679 Avatar answered Mar 16 '23 04:03

user2643679