Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webdriverprefs.json not found - pyinstaller

I have a python program which uses selenium package, and when creating an exe from this using pyinstaller it creates the exe correctly. When trying to open firefox from this app I got the following error:

IOError: [Errno 2] No such file or directory:
'C:\\users\\mohamed\\Temp\\_MEI622\\selenium\\webdriver\\firefox\\webdriver_prefs.json'

I found this solution, but it doesn't work for me:

Py2exe isn't copying webdriver_prefs.json into builds

Any ideas?

like image 648
Mohamed Yousof Avatar asked Jul 02 '26 20:07

Mohamed Yousof


2 Answers

I found a solution for same, when freezing scripts to exe don't use --onefile , use --onedir instead , it will generate one folder for all files and then copy selenium folder in path c:\python27\lib\site-packages\selenium to your app folder and it works correctly

like image 62
Mohamed Yousof Avatar answered Jul 05 '26 09:07

Mohamed Yousof


simply include these (.json & .xpi) files as arbitrary files in your .spec file.

here's what worked for me (you might need to change the paths):

needed_selenium_files = [(r'selenium\webdriver\firefox\webdriver_prefs.json',
                           r'C:\Anaconda\Lib\site-packages\selenium\webdriver\firefox\webdriver_prefs.json',
                          'DATA'),
                         (r'selenium\webdriver\firefox\webdriver.xpi',        
                           r'C:\Anaconda\Lib\site-packages\selenium\webdriver\firefox\webdriver.xpi',
                           'DATA')]

and later on:

coll = COLLECT(exe, a.binaries, needed_selenium_files, ...)

read more on PyInstaller Manual: http://pythonhosted.org/PyInstaller/#toc-class-table-of-contents and http://pythonhosted.org/PyInstaller/#adding-files-to-the-bundle

like image 45
Mordechai L Avatar answered Jul 05 '26 11:07

Mordechai L