我是新的编码,只是不明白这个错误代码的意思

2024-05-13 20:48:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近才开始使用Python 3编写代码。我不知道如何表达我想问的问题,因为我不理解返回的这些错误的任何部分

    Traceback (most recent call last):
  File "C:\Users\Liam McAuley\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\Liam McAuley\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Liam McAuley\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Liam McAuley\AppData\Local\Programs\Python\Python38\shrek.py", line 13, in <module>
    driver = webdriver.Chrome('chromedriver.exe')
  File "C:\Users\Liam McAuley\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\Liam McAuley\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

有人能帮忙吗


Tags: inpyselfliblocalseleniumlineusers
3条回答

系统找不到chromerdriver可执行文件。在使用Windows时,我建议使用可执行文件的完整路径定义:

driver = webdriver.Chrome(executable_path="C:\Users\Liam McAuley\path\to\actual\chromedriver.exe")

或者,您可以通过在命令提示符中键入此命令将chromedriver.exe添加到路径中(确保您以管理员身份运行!)

 setx CHROMEDRIVER=C:\Users\Liam McAuley\path\to\actual\chromedriver.exe

Selenium尝试访问chromdriver,chromdriver是它用来执行

   driver = webdriver.Chrome('chromedriver.exe')

为了使用chromedriver,它必须在路径上。你可以得到chromedriverhere。至于如何向路径添加内容,您可以临时使用SETX

   setx CHROMEDRIVER=path/to/chromedriver.exe

或者,您可以为驱动程序创建一个文件夹,然后按照以下说明将该文件夹永久添加到路径here

从痕迹上看,似乎有两件事出了问题。第一个问题是,python似乎无法找到您指定的文件,因此可能需要检查您的路径。第二个问题是,您的路径上可能没有chromedriver。如果您使用的是windows,则可以通过“环境变量”选项卡将其添加到路径中。您还可以按照here中的步骤进行操作

相关问题 更多 >