我在Mac OS X上使用全局PhantomJS,用于多个Javascript和Pythonselenium项目。第一次,我使用virtualenv设置了一个虚拟环境:
virtualenv Python3.5 Path/To/MyEnvironnement
然后 :
Path/To/MyEnvironnement . bin/activate which phantomjs
…返回我的全局selenium:/Users/Me/.npm-packages/bin/phantomjs
但是每次我打电话:
driver = webdriver.PhantomJS(executable_path=r'/Users/Me/.npm-packages/bin/phantomjs')
我收到此错误:
Traceback (most recent call last): File "/Path/To/MyEnvironnement/script/spider/crawl/Urls.py", line 194, in <module> init_driver() File "/Path/To/MyEnvironnement/script/spider/crawl/Urls.py", line 29, in init_driver driver = webdriver.PhantomJS(executable_path=r'/Users/Me/.npm-packages/bin/phantomjs') File "/Path/To/MyEnvironnement/lib/python3.5/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__ self.service.start() File "/Path/To/MyEnvironnement/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 86, in start self.assert_process_still_running() File "/Path/To/MyEnvironnement/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 99, in assert_process_still_running % (self.path, return_code) selenium.common.exceptions.WebDriverException: Message: Service /Users/Me/.npm-packages/bin/phantomjs unexpectedly exited. Status code was: 127
自从我第一次遇到此问题以来已经过了24小时,而且我阅读了几乎所有可能涉及此问题的帖子。
我试图在我的virtualenv内创建一个nodeenv,但没有成功:在pythonvirtualenv内的Selenium项目中运行phantomjs
我想为时已晚,但是为了解决这个问题,我通过以下方式解决了这个问题:
sudo apt-get install libfontconfig
答案在这里找到:
使用python和selenium连接到phantomJsWebdriver时出现问题