【问题标题】:Python: PyInstaller / AutoPy2Exe with chromedriver_py library exceptionPython:带有 chromedriver_py 库异常的 PyInstaller / AutoPy2Exe
【发布时间】:2023-01-02 15:12:34
【问题描述】:

我正在尝试将一个 python 文件转换为一个 *.exe,其中包含一个库“chromedriver_py”。

在 PyCharm 中我的程序运行完美,没有错误/异常或任何东西,但是当我使用 PyInstaller 或 autopy2exe 将它转换为 exe 时它抛出我,无论它是一个文件还是一个目录(捆绑包)它抛出一个错误:

Traceback (most recent call last):
  File "testscript.py", line 25, in <module>
    from chromedriver_py import binary_path
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "chromedriver_py\__init__.py", line 36, in <module>
  File "chromedriver_py\__init__.py", line 31, in _get_filename
Exception: Couldn't find a binary for your system: windows / amd64. Please create an Issue on github.com/breuerfelix/chromedriver-py and include this Message.

-- 我像这样导入它(使用硒,但我想你可以忽略它):

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.chrome.service import Service
from subprocess import CREATE_NO_WINDOW
from chromedriver_py import binary_path  # chromedriver_py

并在代码中使用它:

# Just a small test function
def test_func():
    chrome_options = Options()
    chrome_options.add_argument("--start-maximized")
    service = Service(binary_path)  # Getting the binary path of Chromedriver
    service.creationflags = CREATE_NO_WINDOW  # No cmd-prompt when selenium's working

    driver = webdriver.Chrome(options=chrome_options, service=service)

我也尝试过将 --hidden-import 与 chromedriver_py 一起使用,遗憾的是它也没有用。

一些细节:

Python 3.10.0
PyInstaller 4.8
chromedriver_py >97, <98
selenium 4.1.0

如果有人有想法,请分享,我将非常感激。

【问题讨论】:

    标签: python selenium selenium-chromedriver pyinstaller


    【解决方案1】:

    嘿,我面临同样的问题,你能找到解决方案吗

    【讨论】:

    • code_lover,请不要添加我也是作为答案。它实际上并没有提供问题的答案。如果您有不同但相关的问题,请ask它(如果它有助于提供上下文,请参考此问题)。如果你对这个具体问题感兴趣,你可以upvote它,留下comment,或者一旦你有足够的reputation就开始bounty
    猜你喜欢
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 2017-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-23
    相关资源
    最近更新 更多