0

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

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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,
            }
    }
)

2 Comments

Thank you for the response, this way I was able to create exe but got some messages below and when I tried to execute exe its doing nothing. The following modules appear to be missing ['Carbon', 'Carbon.Files', '_scproxy', '_sysconfigdata', 'urllib.parse', 'winreg.CloseKey', 'winreg.HKEY_CURRENT_USER', 'winreg.HKEY_LOCAL_MACHINE', 'winreg.OpenKey', 'winreg.OpenKeyEx', 'winreg.QueryValue', 'winreg.QueryValueEx']
*** binary dependencies *** Your executable(s) also depend on these dlls which are not included, you may or may not need to distribute them. Make sure you have the license if you distribute any of them, and make sure you don't distribute files belonging to the operating system. OLEAUT32.dll - C:\WINDOWS\system32\OLEAUT32.dll USER32.dll - C:\WINDOWS\system32\USER32.dll SHELL32.dll - C:\WINDOWS\system32\SHELL32.dll KERNEL32.dll - C:\WINDOWS\system32\KERNEL32.dll ADVAPI32.dll - C:\WINDOWS\system32\ADVAPI32.dll WS2_32.dll - C:\WINDOWS\system32\WS2_32.dll
0

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

3 Comments

Hi, I tried this but somehow its not adding firefox drivers and exe or msi is not able to do anything, is there a way to add explicitly?
It does not add firefox drivers as it's not a Python module/package.As long as you have the firefox drivers installed you wont have a problem but if you really need to distribute along with that then look up InnoSetup.
Thanks I tried it again and I built exe and when I try to double-click exe its doing nothing. I tried to run it as Administrator too. I also built msi I could install msi but on program files same issue .exe doesnt do anything.
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.