Showing posts with label Selenium. Show all posts
Showing posts with label Selenium. Show all posts

Thursday, July 24, 2014

How to make py2exe include external files (such as Selenium)

If you read the full documentation of py2exe you might still not have completely clear how to perform some tasks with it.

The snippet to put on the "setup.py" file to generate the py2exe executable from the python source "run.py" is:

from distutils.core import setup
import py2exe

wd_path = 'C:\\Python27\\Lib\\site-packages\\selenium\\webdriver'
required_data_files = [('selenium/webdriver/firefox',
                        ['{}\\firefox\\webdriver.xpi'.format(wd_path), '{}\\firefox\\webdriver_prefs.json'.format(wd_path)])]

setup(
    console = ['run.py'],
    data_files = required_data_files,
    options = {
               "py2exe":{
                         "skip_archive": True,
                        }
               }
)