Python 硒铬驱动程序路径错误不存在';无法解决

Python 硒铬驱动程序路径错误不存在';无法解决,python,selenium,path,selenium-chromedriver,Python,Selenium,Path,Selenium Chromedriver,因此,我一直在尝试将YouTube教程()作为一个快速有趣的项目介绍给selenium,但我已经遇到了一个问题。每当我运行我的代码时,我总是会遇到这样的错误:“chromedriver”可执行文件需要在PATH中。我已经搜索了很多次这个问题,将chromedriver.exe移动到C:/目录以使事情变得更简单,并且尽我所能处理环境变量,但仍然无法解决这个问题。请帮帮我! 这是我正在运行的代码 # This bot is made following this YouTube tutorial:

因此,我一直在尝试将YouTube教程()作为一个快速有趣的项目介绍给selenium,但我已经遇到了一个问题。每当我运行我的代码时,我总是会遇到这样的错误:“chromedriver”可执行文件需要在PATH中。我已经搜索了很多次这个问题,将chromedriver.exe移动到C:/目录以使事情变得更简单,并且尽我所能处理环境变量,但仍然无法解决这个问题。请帮帮我! 这是我正在运行的代码

# This bot is made following this YouTube tutorial: https://www.youtube.com/watch?v=BGU2X5lrz9M
# All the import crap
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time


driver = webdriver.Chrome("C:\\chromedriver.exe")


class InstaBot:

    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.driver = webdriver.Chrome()

    def close_browser(self):
        self.driver.close()

    def login(self):
        global driver
        driver = self.driver
        driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher")
        time.sleep(2)
        # "//a[@href'accounts/login']"
        # "//input[@name='username']"
        # "//input[@name='password']"


georgeIG = InstaBot("NotGonnaShowToStackOverflow", "NotGonnaShowToStackOverflow")
georgeIG.login()
以下是我对环境变量的尝试。


在链接到的视频中,命令
pip install selenium
将处理将驱动程序添加到路径的操作

我假设您已尝试在windows上模拟此操作,但在理解如何使用
PATH
变量时遇到了问题。讨论如何注册.exe以使其全局可用,这可能会对您有所帮助

不能直接在
PATH
变量中注册可执行文件,因为
PATH
应该只包含目录。尝试将
chromedriver.exe
文件移动到
路径中的一个文件夹中,然后再次运行命令

或者,您可以创建一个文件夹,例如
c:\buildtools
,将其添加到
路径中,然后将
chromedriver.exe
放入该文件夹中,然后再次运行命令。

尝试此设置:

# Setup our chrome preferences.
chromeOptions = webdriver.ChromeOptions()
# Change this variable to the path of the chromedriver you downloaded.
chromedriver = "D:\Downloads\chromedriver_win32\chromedriver.exe"

driver = webdriver.Chrome( executable_path = chromedriver, 
chrome_options = chromeOptions )

对我个人来说,这是一个在设置环境变量后重新启动机器的问题。我知道这听起来很疯狂,但对我来说,它奏效了


我知道这个问题已经解决了。我只是想我会为将来遇到这个问题的任何人提供我自己的意见。

我100%确定这是有效的,因为我这样做了,忘记将驱动程序更改到新目录,但它不起作用,然后我采用了Felipe的解决方案,这也起作用了,所以你的解决方案也可能起作用。