Sunday 7 March 2021

Getting chrome driver not in path when moving my selenium executable to another computer

I wrote a small automation script using Python and Selenium Web Driver and I made it into an executable and the executable worked fine on my computer but when I tried it on another computer I got that chromedriver isn't in path (note: I included chromedriver using the add binary command and both computers are running the same operating system: Mac OS)

I am not quite sure why this happened, my suspicion is the following:

In my .py code I used the following two lines to initiate the chromedriver

path = "/Users/sergio/chromedriver"
driver = webdriver.Chrome(path)

However, the other computer doesn't even have this path so might be causing it even has this path. Now one might suggest simply using driver = webdriver.Chrome() but here comes the bigger problem: I tried having my chromedriver in a system path like /usr/local/bin and when I did that driver = webdriver.Chrome() worked but compiling the program using pyinstaller didn't work, I ran:
pyinstaller --onefile --noconsole --add-binary 'usr/local/bin/chromedriver:.' finalregtool.py
but I got a lot of errors including Unable to find "/Users/sergio/usr/local/bin/chromedriver" when adding binary and data files

This led to me thinking that pyinstaller automatically adds /Users/sergio to the given path which makes my path wrong so I had to use something inside /Users/sergio , I tried putting my chromedriver in Applications but compilation resulted in not finding the path again, for some reasons compilation worked when the path was /Users/sergio/chromedriver so I went with this path but the code didn't work anymore (chromedriver not found in path) so I had to specify the path manually.

Now I am kind of stuck in a deadlock not knowing what to do. Any help would be appreciated. I hope my explanation was clear enough.

My only end goal is compiling my selenium script and running it on other computers without having them install anything extra, I don't care how this should be done so if anyone has a solution outside pyinstaller I don't mind.

Update: added a bounty



from Getting chrome driver not in path when moving my selenium executable to another computer

No comments:

Post a Comment