简体   繁体   中英

OSError: [WinError 193] %1 is not a valid Win32 application error using GeckoDriver and Firefox through Selenium and Python on Windows

I created script with selenium in Ubuntu and works just fine there, but when I moved it to windows10, I get lots of error and I tried to fix it one by one until I see this error. I've been looking for the solution to this problem but I am unable to resolve this error.

Traceback (most recent call last):
  File "D:/Users/b/Documents/Python/Bolt/GUI.py", line 180, in start
    driver = l.start_chime()  # start chime
  File "D:\Users\b\Documents\Python\Bolt\Login.py", line 87, in start_chime
    self.chime_driver = webdriver.Firefox(executable_path=self.PATH)
  File "D:\Users\b\Documents\Python\Python3.8\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
    self.service.start()
  File "D:\Users\b\Documents\Python\Python3.8\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "D:\Users\b\Documents\Python\Python3.8\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "D:\Users\b\Documents\Python\Python3.8\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
  File "C:\Program Files\JetBrains\PyCharm 2020.1.2\plugins\python\helpers\pydev\_pydev_bundle\pydev_monkey.py", line 551, in new_CreateProcess
    return getattr(_subprocess, original_name)(app_name, patch_arg_str_win(cmd_line), *args)
OSError: [WinError 193] %1 is not a valid Win32 application

This is happen when I tried to open webdriver using selenium.

self.myday_driver = webdriver.Firefox(executable_path=self.PATH)

and is there any method to move script from Ubunto to Windows without getting error?

I will try to help you answer your last question:

and is there any method to move script from Ubunto to Windows without getting error?

Yes, have you heard about docker? https://www.docker.com/ Essentially, docker will create isolated environments that will run in every machine that has docker installed. These environments are configurable inside a dockerfile, basically, you need to follow these steps:

  • Install docker on both machines. I have used on Windows and RH to automate all this process and minimize erros.
  • Create a docker file , the structure will be something like:
FROM ubuntu:18.04
COPY . /app
RUN make /app
CMD python /app/app.py
  • So it will create an environment based on a ubuntu image
  • copy all files in your current directory (.) to /app (remember this will be a ubuntu image, so you have a standard folder structure with /etc /home, etc.)
  • run command make (in your case could be install some dependency using pip)
  • run python command.

You also can find python images ready for usage, so instead of ubuntu:latest you could get a image linux with python installed and then you just install your dependencies.

This is a great tool for a developer, I recommend looking into it, read documentation to understand concepts and it will ease your life.

Hope it helps.

This error message...

OSError: [WinError 193] %1 is not a valid Win32 application

...implies that the underlying OS doesn't recognizes %1 ie the system variable PATH as a valid Win32 application ie a executable binary .


To initiate a Selenium driven GeckoDriver controlled Firefox session you need to:

  • Download the latest version of GeckoDriver binary version, place it in your system.

  • Next in your code block you need to mention the absolute path of the binary through the Key executable_path as follows:

     from selenium import webdriver self.myday_driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM