2

I having trouble installing PhantomJS to my project Following the suggestions from the similar question from so I defined the $PATH variable with executable path

cd Users/zkid18/project/venv/venv_name/lib/python3.6/site-packages/phantomjs-2.1.1/bin 
export PATH=$PWD

Then I try to create a driver with a virtual browser

import from selenium import webdriver
browser = webdriver.PhantomJS()

On this step I got an error

No such file or directory: 'phantomjs': 'phantomjs'

What I am missing?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Daniel Chepenko
  • 2,229
  • 7
  • 30
  • 56
  • 1
    Check whether you've downloaded 32-bit PhantomJS version for 32-bit OS or 64-bit version for 64-bit OS... Also it's better to append directory to PATH (`export PATH=$PATH:$PWD`) instead of re-define PATH... – Andersson Jan 10 '19 at 16:50
  • Possible duplicate of [PhantomJS with Selenium error: Message: 'phantomjs' executable needs to be in PATH](https://stackoverflow.com/questions/37903536/phantomjs-with-selenium-error-message-phantomjs-executable-needs-to-be-in-pa) – stovfl Jan 10 '19 at 18:05
  • `export PATH=$PWD` will likely make your shell unusable. – SiKing Jan 10 '19 at 18:51
  • @Andersson I use mac os x, so I guess only one version availbale – Daniel Chepenko Jan 11 '19 at 00:08
  • Check my answer, It works for both windows and mac os. – Jiya Oct 20 '20 at 02:30
  • Check this answer. This will work fine https://stackoverflow.com/a/64437609/12017533 – Jiya Oct 20 '20 at 03:27

2 Answers2

2

You need to give the path:

browser = webdriver.PhantomJS(executable_path='Complete path/to/phantomjs')

To find it use export PATH=${PATH:+$PATH:} in the command line as @Anderson commented.

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
  • 1
    If this is a dup, please post it as a dup (it looks like you already did) and then don't answer because it causes confusion to new (and potentially other) users. – JeffC Jan 10 '19 at 17:01
  • @JeffC I did but it looks like it doesn't answer OP's question... take a look at the flag I raised – Moshe Slavin Jan 10 '19 at 17:02
  • @MosheSlavin I'm a bit confused about using defining PATH properly. Why should I append path instead of redefining it? After `export PATH=$PATH:$PWD` I run `$PATH` in the command line bash: `/usr/bin:/bin:/usr/sbin:/sbin:/Users/zkid18/project/venv/venv_name/lib/python3.6/site-packages/phantomjs-2.1.1/bin: No such file or directory` Seems I did something wrong – Daniel Chepenko Jan 11 '19 at 00:17
1

This error message...

No such file or directory: 'phantomjs': 'phantomjs'

...implies that the program was unable to locate the phantomjs binary.

As you are on MAC OS X you need to download phantomjs-2.1.1-macosx.zip from Download PhantomJS page and extract (unzip) the content within your system. Next you can mention the absolute path of phantomjs binary passing the argument executable_path as follows:

  • MAC OS X example:

    from selenium import webdriver
    
    driver = webdriver.PhantomJS(executable_path='/path/to/phantomjs-2.1.1-xxx/bin/phantomjs')
    driver.get('https://www.google.com/')
    print(driver.title)
    driver.quit()
    
  • Windows OS example:

    from selenium import webdriver
    
    driver = webdriver.PhantomJS(executable_path=r'C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe')
    driver.get('https://www.google.com/')
    print(driver.title)
    driver.quit()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352