9

I have created a small web scraping app using Selenium & chromedriver for a project that outputs the content into an excel file. The people I did this app for unfortunately aren't the most tech-savvy.

So my question is how can I share this app with these people?

I looked into py2exe.org, but it doesn't take the chromedriver into account when creating the executable. Any better ways of doing this, without these people having to add the files manually to their "usr/bin"?

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
user2868900
  • 721
  • 3
  • 9
  • 29

1 Answers1

9

You can do this with the help of pyinstaller : Below is the solution which work on Windows but pyinstaller says its capable of working on Mac OS also.

Steps are:

  1. Open Command prompt
  2. Go to the project path in cmd where the script is present
  3. type pyinstaller Scriptname.spec Scriptname.py (Enter y/yes if prompt on screen)
  4. The build will be at 'path to project'\dist\Scriptname

Note you need to provide the details of chromedriver in Scriptname.spec when passing the

Sample content of spec file:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['Scriptname.py'],
             pathex=['Pathofproject'],
             binaries=[('C:\\Python27\\chromedriver.exe', '**.\\selenium\\webdriver**')],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='createEVIPOrg_Automation_new',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='**scriptname**')

You need to update the Scriptname, project path where you script lies, path of chromedriver in spec file

newdevon
  • 3
  • 2
thebadguy
  • 2,092
  • 1
  • 22
  • 31
  • 1
    Thanks! I'm trying to use the --onefile command, but then it doesn't take the binaries into account. I only get the error " FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'". Any workaround for this? – user2868900 Apr 16 '18 at 14:31
  • you need to provide the path of chromedriver of your machine under binaries of spec file – thebadguy Apr 16 '18 at 14:52
  • 1
    I currently have the following: `binaries=[('/usr/local/bin/chromedriver', '.')],` And then the following line in the .py script: `cdriver_path = os.path.join(sys._MEIPASS, "chromedriver")` `driver = webdriver.Chrome(cdriver_path)` - I still get the same error, seems like I can't point to the output folder when it is --onefile? – user2868900 Apr 16 '18 at 16:08
  • 2
    solved it! The path worked eventually, the key was to execute the file by using "pyinstaller --onefile scriptname.spec" (excluding scriptname.py). Then it bundled everything nicely – user2868900 Apr 16 '18 at 22:34
  • 1
    Can you please help with firefox, I set `binaries=[("C:\\python36\\geckodriver.exe", '.')],`, I get ** No module named 'selenium'** – Heinz Jul 19 '19 at 16:07