Reputation: 25
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?
Upvotes: 1
Views: 1916
Reputation: 193168
This error message...
OSError: [WinError 193] %1 is not a valid Win32 application
...implies that the underlying OS doesn't recognizes %1
i.e. the system variable PATH
as a valid Win32 application i.e. 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')
Upvotes: 0
Reputation: 216
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:
FROM ubuntu:18.04
COPY . /app
RUN make /app
CMD python /app/app.py
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.
Upvotes: 1