====== 2025.02.09 Python OSError: [WinError 193] %1 は有効な Win32 アプリケーションではありません。 ====== PythonでChrome Driverを読み込む時にエラーになる。 ===== ソース ===== from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service options = Options() driver_path = ChromeDriverManager().install() print(f"ChromeDriver is installed at: {driver_path}") global_service = Service(driver_path) driver = webdriver.Chrome(service=global_service, options=options) ===== Error ===== OSError: [WinError 193] %1 は有効な Win32 アプリケーションではありません。 ===== 対応方法 ===== driverのパスをprintfしてみると、THIRD_PARTY_NOTICES.chromedriverになってる。 C:\Users\s-matsui\.wdm\drivers\chromedriver\win64\132.0.6834.160\chromedriver-win32/THIRD_PARTY_NOTICES.chromedriver そこで、Pathを修正するして、chromedriver.exeに変えてあげると動作しました。 from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service options = Options() driver_path = ChromeDriverManager().install() ## Pathを修正 driver_path = driver_path.replace("THIRD_PARTY_NOTICES.chromedriver", "chromedriver.exe") print(f"ChromeDriver is installed at: {driver_path}") global_service = Service(driver_path) driver = webdriver.Chrome(service=global_service, options=options) {{tag>日記 Python Selenium}}