V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
redhatping
V2EX  ›  Python

代码运行 MAC 没问题, 去跑 ubuntu 报错了,找不到办法(爬虫问题,selenuim 调用)

  •  
  •   redhatping · 2016-08-02 12:43:14 +08:00 · 6242 次点击
    这是一个创建于 2831 天前的主题,其中的信息可能已经有所发展或是发生改变。
    
       driver = webdriver.Firefox(firefox_profile=ffprofile)
      File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 65, in __init__
        self.service.start()
      File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 71, in start
        os.path.basename(self.path), self.start_error_message)
    selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
    
    Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x3359310>> ignored
    
    

    报错信息如上..

    环境: Ubuntu sever

    Selenium : 3.0 ( pip install -U selenium)

    Firefox ( usr/bin , sudo apt-get update )

    报错原因; MAC OS 执行没有问题, 换了环境去了 Ubuntu 出错了. 努力 GOOGLE 没找到办法, 谢谢大家了.

    29 条回复    2016-08-03 05:34:34 +08:00
    ykrl089
        1
    ykrl089  
       2016-08-02 12:52:52 +08:00
    查下文件或者路径的大小写问题
    redhatping
        2
    redhatping  
    OP
       2016-08-02 12:54:00 +08:00
    @ykrl089 没明白.
    xchange
        3
    xchange  
       2016-08-02 13:20:34 +08:00
    提示里面不是说了'geckodriver' executable needs to be in PATH 吗?
    redhatping
        4
    redhatping  
    OP
       2016-08-02 13:22:44 +08:00
    @xchange firefox 在 usr/bin 下面啊... 么有问题啊 echo $PATH /usr/bin: 也有啊..
    Garantion
        5
    Garantion  
       2016-08-02 13:24:07 +08:00
    你确定是 ubuntu server ?我记得我当时用 Selenium 的时候没有图形界面是无法运行的。
    redhatping
        6
    redhatping  
    OP
       2016-08-02 13:40:45 +08:00
    @Garantion 我安装了图形界面啊.. xfce
    ykrl089
        7
    ykrl089  
       2016-08-02 13:49:41 +08:00
    @redhatping mac 系统文件名和路径不区分大小写, linux 一般是区分大小写的,
    也就是说在 linux 下 geckodriver != Geckodriver
    你自己看下文件名和路径名有没有错误
    redhatping
        8
    redhatping  
    OP
       2016-08-02 14:00:01 +08:00
    @ykrl089 这么说 , 我运行以下代码就有问题了
    ``python

    from selenium import webdriver
    driver = webdriver.Firefox()

    ```

    就会报错了...

    这个不可能是大小写出现的吧.
    ykrl089
        9
    ykrl089  
       2016-08-02 14:14:26 +08:00
    @redhatping 你看下 /webdriver.pyservice.py 的 65 行和 71 行是什么呗
    eclipselu
        10
    eclipselu  
       2016-08-02 14:18:37 +08:00
    看起来是 geckodriver 没在 PATH 里,实在不行换个别的浏览器试试看?比如 ChromeDriver ,或者 PhantomJS
    redhatping
        11
    redhatping  
    OP
       2016-08-02 14:27:55 +08:00
    @eclipselu 对啊, 但是 firefox 不是默认的嘛.. geckodriiver 也在 /usr/bin/firefox (firefox)
    redhatping
        12
    redhatping  
    OP
       2016-08-02 14:38:03 +08:00
    @ykrl089
    #65 self.service.start()
    #71 os.path.basename(self.path), self.start_error_message


    这两个判断, 都是系统路径的问题. 但是我 firefox 确实已经安装了 . 就在 usr/bin 里面
    mrwangrj
        13
    mrwangrj  
       2016-08-02 14:49:36 +08:00
    好巧今早遇到了长得差不多的问题,我这边是用的 PhantomJS ,换了个环境发现没有在 PATH 里
    redhatping
        14
    redhatping  
    OP
       2016-08-02 14:58:21 +08:00
    @mrwangrj 你是怎么解决的. 我$PATH 也在 USR/BIN 里面啊..
    mrwangrj
        15
    mrwangrj  
       2016-08-02 15:09:36 +08:00
    @redhatping 是不是需要 /usr/bin/firefox 搞到$PATH 里?
    eclipselu
        16
    eclipselu  
       2016-08-02 17:12:15 +08:00
    @redhatping 不太清楚 Ubuntu 下面是怎么样,好像我当时用的时候是单独装了一个 geckodriver
    https://github.com/mozilla/geckodriver 。就是 Firefox 和 geckodriver 都要有。
    gimp
        17
    gimp  
       2016-08-02 17:20:10 +08:00
    看你的 Firefox 版本,如果太高了会报错, selenium 对新版火狐支持不好

    你也可以安装个 chrome ,然后下载个 chrome driver 来用( http://chromedriver.storage.googleapis.com/index.html?path=2.22/)
    redhatping
        18
    redhatping  
    OP
       2016-08-02 17:27:51 +08:00
    @gimp MAC 我也是新版本, 似乎没撒问题. 就是叫降低版本看看?
    redhatping
        19
    redhatping  
    OP
       2016-08-02 17:41:18 +08:00
    @eclipselu 我试试
    IMRES
        20
    IMRES  
       2016-08-02 17:49:32 +08:00
    检查`which geckodriver`得到的目录是否在"$PATH"中
    Garantion
        21
    Garantion  
       2016-08-02 17:50:58 +08:00
    @redhatping 我之前也是在 MAC 下开发的,不过移动到的就是普通的 ubuntu 14.04 LTS , server 装了界面这个就不清楚了。
    sodatea
        22
    sodatea  
       2016-08-02 17:56:41 +08:00 via iPhone
    geckodriver 跟 firefox 又不是一回事……
    redhatping
        23
    redhatping  
    OP
       2016-08-02 18:02:26 +08:00
    @IMRES 没这个东西 whick 是空的
    redhatping
        24
    redhatping  
    OP
       2016-08-02 18:02:51 +08:00
    @eclipselu 没看懂怎么安装 geckodriver
    redhatping
        25
    redhatping  
    OP
       2016-08-02 18:03:14 +08:00
    @sodatea 对啊, 似乎是两个东西 请问怎么办呢
    eclipselu
        26
    eclipselu  
       2016-08-02 18:24:30 +08:00   ❤️ 1
    @redhatping https://github.com/mozilla/geckodriver/releases 这里下载一个 linux64 下的放到 PATH 下的随便一个目录试试看?
    eclipselu
        27
    eclipselu  
       2016-08-02 18:24:55 +08:00
    @redhatping 或者自己编译一个
    redhatping
        28
    redhatping  
    OP
       2016-08-02 18:36:33 +08:00
    @eclipselu 好好 试试
    redhatping
        29
    redhatping  
    OP
       2016-08-03 05:34:34 +08:00
    @eclipselu 解决了 就是这个问题

    mark:

    answer: download geckodriver to /usr/bin .
    the urllink of geckodriver is github.com/mozilla/geckodriver releases.

    ubuntu server .
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2218 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:57 · PVG 13:57 · LAX 22:57 · JFK 01:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.