Ask coding questions

← Back to all posts
Cannot use selenium web driver because phantomjs is not in path
h
Necrodragon41 (3)

Hi! I'm trying to use selenium on my code but i cannot because phantomjs is not in path.

Here is my log:

/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/phantomjs/webdriver.py:49: UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
  warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless '
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'phantomjs'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "animeflv.py", line 257, in <module>
    print(json.dumps(get_anime_data('https://www3.animeflv.net/anime/majutsushi-orphen-hagure-tabi-kimluckhen'), indent=4))
  File "animeflv.py", line 154, in get_anime_data
    driver = webdriver.PhantomJS()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 56, in __init__
    self.service.start()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH.

Basically, phantomjs is not in path. How can I fix it?

Comments
hotnewtop
Coder100 (17027)

However, you can use webbot, which uses selenium, weird right?

import webbot
web = webbot.Browser()
web.go_to('https://repl.it/')

Docs

Coder100 (17027)

selenium must be using phantomjs which is apparantly a different lib. Try installing it with

npm i phantomjs

something like that, or maybe it just doesn't work.

RYANTADIPARTHI (6001)

did you install it?

pip install PACKAGE

if that doesn't work, then it's probably not available in repl.it

Necrodragon41 (3)

@RYANTADIPARTHI its already installed. Its like one of those packages that already comes with python

RYANTADIPARTHI (6001)

@Necrodragon41 maybe it's not available on repl.it

Necrodragon41 (3)

@RYANTADIPARTHI Its available on replit, I have searched

[deleted]

can I see your code to see what's the problem?

Necrodragon41 (3)

@XThacker

driver = webdriver.PhantomJS()
html = driver.get(link)
soup = bs.BeautifulSoup(html, 'lxml')
[deleted]

@Necrodragon41 did you install selenium

Necrodragon41 (3)

@XThacker yeah. Its already installed. Notice that the exception is from selenium

[deleted]

@Necrodragon41 then...I dunno :(

Necrodragon41 (3)

@XThacker basically i need to add phantomjs to path
'phantomjs' executable needs to be in PATH.
Do you know how can I do that?