由于 geckodriver,导入 matplotlib、glob、pylab 时出错

Error during import matplotlib, glob, pylab because of geckodriver

当我尝试导入 matplotlib 或 glob 或 pylab 时,它会打开 geckodriver window 并且 geckodriver 打开 firefox 并在其上打开 google 页面。 在那之后,它给出了以下错误。

Traceback (most recent call last):
  File "<pyshell#27>", line 1, in <module>
    from pylab import *
  File "C:\Users\rahulku\AppData\Local\Programs\Python\Python36\lib\site-packages\pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "C:\Users\rahulku\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\__init__.py", line 122, in <module>
    from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
  File "C:\Users\rahulku\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\cbook.py", line 19, in <module>
    import glob
  File "C:/Users/rahulku/AppData/Local/Programs/Python/Python36\glob.py", line 13, in <module>
    driver = webdriver.Firefox(executable_path=r'C:\Users\rahulku\AppData\Local\Temp\geckodriver.exe')
  File "C:\Users\rahulku\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 154, in __init__
    keep_alive=True)
  File "C:\Users\rahulku\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 140, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Users\rahulku\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 229, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\rahulku\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
    self.error_handler.check_response(response)
  File "C:\Users\rahulku\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Failed to start browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe: other os error

从下面看你的问题很明显

  File "C:/Users/rahulku/AppData/Local/Programs/Python/Python36\glob.py", line 13, in <module>
    driver = webdriver.Firefox(executable_path=r'C:\Users\rahulku\AppData\Local\Temp\geckodriver.exe')

如您所见,您已经创建了自己的 glob.py 文件,该文件干扰了 import glob 语句。您永远不应该创建与系统级包名称匹配的文件名,并将它们也放在 python 路径中。

C:/Users/rahulku/AppData/Local/Programs/Python/Python36\glob.py 重命名为 C:/Users/rahulku/AppData/Local/Programs/Python/Python36\glob_custom.py,这应该可以解决问题