Priyank
Priyank

Reputation: 1

How to create .exe for .py file created in selenium web driver?

So far I have used Py2exe but not sure how to add selenium web driver dependencies related to firefox and other import package I used in my script.

I also explored Pyinstaller but it failed on adding dependencies.

I am doing it for the first time so please suggest how to do it properly.

Thank You

Upvotes: 0

Views: 2700

Answers (4)

SunilThorat
SunilThorat

Reputation: 1748

You can use pyinstaller or cx_freeze to create executable files of python scripts/applications.

Command of pyinstaller:

pyinstaller.exe --onefile --windowed <python file name>

Upvotes: 0

Vijay
Vijay

Reputation: 106

You need to specify the location of selenium webdriver in setup.py file.

Following code should help:

from distutils.core import setup
import py2exe

# Change the path in the following line for webdriver.xpi
data_files = [('selenium/webdriver/firefox', ['C:/Python27/Lib/site-packages/selenium/webdriver/firefox/webdriver.xpi'])]

setup(
    name='Name of app',
    version='1.0',
    description='Description of app',
    author='author name',
    author_email='author email',
    url='',
    windows=[{'script': 'test.py'}],   # the main py file
    data_files=data_files,
    options={
        'py2exe':
            {
                'skip_archive': True,
                'optimize': 2,
            }
    }
)

Upvotes: 1

manikantanr
manikantanr

Reputation: 574

You can use py2exe to pack your python script as a standalone executable.

By default py2exe packs all imported packages. If you want to pack browser also, you might have to use portable browser.

You can add portable browser as data to your py2exe package and specify the realative path while initializing webdriver.

You can specify firefox binary executable using executable_path argument in below class.

webdriver.Firefox(self, firefox_profile=None,firefox_binary=None, timeout=30, capabilities=None, proxy=None, executable_path=geckodriver,  firefox_options=None, log_path=geckodriver.log)  

** I dont have option to add comment , so writing as answer.

Upvotes: 1

Taufiq Rahman
Taufiq Rahman

Reputation: 5704

You may want to try CX_Freeze,it adds all necessary packages/dependencies required for your code to run as a single .exe

pip install cx_Freeze

Upvotes: 0

Related Questions