Alex Alex - 1 year ago 270
Python Question

Selenium - 'Service' object has no attribute 'process'

I am attempting to run a simple program on an Ubuntu 16.04 instance using Python 3.5. The program is below;

from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.PhantomJS("p/phantomjs")
s = BeautifulSoup(driver.page_source, "lxml")
except AttributeError:

All the modules are installed correctly. However, when I run the program, I receive the following errors:

Traceback (most recent call last):
File "", line 4, in <module>
driver = webdriver.PhantomJS("p/phantomjs")
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/phantomjs/", line 52, in __init__
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python3.5/", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x7fb05cd964a8>>
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/", line 163, in __del__
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'

It seems as though it is an issue with Selenium rather than with PhantomJS. However, I have no idea how to make the program work properly.

In other questions similar to this, the issue seems to be with closing the headless instance. However, this error is received as soon as I try to instantiate PhantomJS.

How can this be fixed?

Answer Source

If p folder (as you've mentioned) located in the same directory as your script, then you might need to start your code with something like

from bs4 import BeautifulSoup
from selenium import webdriver
import os

path_to_phantom_js = os.path.dirname(__file__) + '/p/phantomjs'
driver = webdriver.PhantomJS(path_to_phantom_js)

P.S. If it not works, tell me output of print(path_to_phantom_js)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download