0
votes

I have a python (34) script which uses selenium package, and when creating an exe using py2exe I have the following error

webdriver_prefs.json not found

I found the following solution, but I dont get it :

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

Here's my setup.py

from distutils.core import setup
import py2exe

data_filesR = [('selenium/webdriver/firefox', ['C:/Python34/Lib/site-packages/selenium/webdriver/firefox/webdriver.xpi','C:/Python34/Lib/site-packages/selenium/webdriver/firefox/webdriver_prefs.json'])]

setup(
    name='Test',
    version='1.0',
    description='General description of app',
    author='author name',
    author_email='author email',
    url='',
    console = ['firefox.py'],
    data_files=data_filesR,
    options={
        'py2exe':
            {

                "skip_archive": True,
                "unbuffered": True,
                'optimize': 2,
            }
    },
     requires=['selenium'],
)
2

2 Answers

0
votes

I met and have solved the similar problem:

  1. Copy webdriver.xpi and webdriver_prefs.json into your exe directoy.
  2. Modify C:\Python27\Lib\site-packages\selenium\webdriver\firefox\firefox_profile.py:

    Change "os.path.join(os.path.dirname(file)" into -> "os.path.join(os.path.dirname(file), '..\..\..\..\'", has two places.

0
votes

The following worked.

Edit firefox_profile.py: WEBDRIVER_EXT, WEBDRIVER_PREFERENCES:

if getattr(sys, 'frozen', False):
    WEBDRIVER_EXT = os.path.join(os.path.dirname(sys.executable), "webdriver.xpi")
    WEBDRIVER_PREFERENCES = os.path.join(os.path.dirname(sys.executable), "webdriver_prefs.json")
elif __file__:
    WEBDRIVER_EXT = os.path.join(os.path.dirname(__file__), "webdriver.xpi")
    WEBDRIVER_PREFERENCES = os.path.join(os.path.dirname(__file__), "webdriver_prefs.json")

goto the line with open(... and replace with with open(WEBDRIVER_PREFERENCES) as default_prefs.