【问题标题】:Pyinstaller gives " 'chromedriver.exe' executable needs to be in PATH" when the .exe is ran, but the actual python script works fine运行 .exe 时,Pyinstaller 给出“'chromedriver.exe' 可执行文件需要在 PATH 中”,但实际的 python 脚本工作正常
【发布时间】:2020-04-25 15:37:25
【问题描述】:

所以我有一个使用 selenium 的 python 脚本,当我运行它时一切正常,但我想把它变成一个 .exe 文件,所以我使用了 pyinstaller。我制作了规范文件,但是当我实际运行 .exe 时,我得到chromedriver.exe' executable needs to be in PATH,而通常我在运行 python 脚本时没有得到它

这是我设置路径的实际 python 脚本的代码 sn-p。

path = os.getcwd()        
    if (browser == 'c'):
        driver_path = path + '//chromedriver_win32//chromedriver.exe'
        options = webdriver.ChromeOptions()
        options.add_argument("--mute-audio")
        if (hidden == 'T'): options.add_argument('headless')
        driver = webdriver.Chrome(executable_path=driver_path, options=options)
    if (browser == 'f'):
        driver_path = path + '//geckodriver-v0.26.0-win64//geckodriver.exe'
        options = webdriver.FirefoxOptions()
        options.add_argument("--mute-audio")
        if (hidden == 'T'): options.add_argument('headless')
        driver = webdriver.Firefox(executable_path=driver_path, options=options)

如果您需要更多代码,请告诉我。

【问题讨论】:

  • 此代码使用os.getcwd(),因此请确保您的.exe 文件与os.getcwd() 位于同一路径中,任何其他路径都不会让您的代码像chromedriver.exe 路径一样工作不正确。
  • 通过将 driver_path 硬编码到 chromedriver 的绝对路径来尝试代码。这里最好的解决方案是将这个绝对路径存储为环境变量,然后在代码中使用。
  • 安装程序是否以其他用户身份运行?所以其他用户会有不同的 PATH,ChromeDriver 可能不在该用户的路径中,但它是给你的。
  • @GregBurghardt 不,它不是作为其他用户安装的,我认为这不是问题。
  • @CavinDsouza nvm 你是对的。我是个白痴,忘了实际添加目录 lmao。谢谢!

标签: python selenium selenium-webdriver exe pyinstaller


【解决方案1】:

带有 chromepath 的目录不在正确的位置。确保仔细检查您的目录层次结构。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    • 2021-03-05
    • 2020-12-02
    • 2020-10-29
    相关资源
    最近更新 更多