3

After updating the Pyinstaller spec file as suggested in the answer here (How to include chromedriver with pyinstaller?), chromedriver is still not being accessed from the generated app file. Could the issue be with .\\selenium\\webdriver? That was copied from the answer and I'm not sure it's specific to a Windows OS.

Running the UNIX executable in terminal works, accessing chromedriver.

The full spec file is:

# -*- mode: python -*-

block_cipher = None


a = Analysis([‘scriptname.py'],
             pathex=['/Users/Name/Desktop'],
             binaries=[('/usr/local/bin/chromedriver', '.\\selenium\\webdriver')],
             datas=None,
             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,
          a.binaries,
          a.zipfiles,
          a.datas,
          name=‘app name’,
          debug=False,
          strip=False,
          upx=True,
          console=False )
app = BUNDLE(exe,
             name=‘appname.app',
             icon=None,
             bundle_identifier=None)

The line pyinstaller appname.spec scriptname.py --windowed --onefile is used in terminal to generate the app.

Community
  • 1
  • 1
ballade4op52
  • 2,142
  • 5
  • 27
  • 42
  • 1
    Yes, '.\\selenium\\webdriver' denotes a Windows relative path. It is where to place the chromedriver binary in the bundle. On Unix, it would be ./selenium/webdriver. However, I tried with this on Windows, and it still put chromedriver there. Do you have the dist/selenium/webdriver dirs with chromedriver executable in the generated bundle? – monami Dec 07 '16 at 21:50
  • Thanks, that helps. However, presently the app works if the chromedriver is just placed in /usr/bin (instead of /usr/local/bin), apparently irrespective of what is placed in the spec file. Do you know if chromedriver could be bundled in the resulting app/exe file? – ballade4op52 Dec 07 '16 at 22:01
  • 1
    But does the chromedriver executable exist in "bundlepath"/dist/selenium dir after running pyinstaller? How do you setup chromedriver in your python code? When it's bundled, you don't use PATH, but set the path to chromedriver something like this (it's a remote example): `dir = os.path.dirname(__file__) chrome_path = os.path.join(dir, 'selenium','webdriver','chromedriver.exe') service = service.Service(chrome_path) ... ` – monami Dec 08 '16 at 19:46
  • I'll look into this when I can. If interested, [this](http://stackoverflow.com/questions/41030257/is-there-a-way-to-bundle-a-binary-file-such-as-chromedriver-with-a-single-file) is a new question linking to this post. – ballade4op52 Dec 08 '16 at 20:07
  • 1
    Should selenium show up in the dist directory if generating for 'onefile'? That's fine if it's not needed to run the app/exe file. chromedriver is accessed implicitly in the code, and works as it's in the path. If it's possible to have chromedriver bundled in the app/exe file, I'll try going along these lines (verifying that I can remove chromedriver from PATH and it still works), and perhaps you could submit something as an answer. – ballade4op52 Dec 08 '16 at 20:28
  • Sorry, I didn't realize I had already submitted the link to the new question on a different post you were the recipient of. – ballade4op52 Dec 08 '16 at 20:36
  • 1
    I don't know what it should look like when using `--onefile`. But interestingly, I got the same file structure when running with `--onefile`. So I have dist/selenium/webdriver dirs in both cases. (Did you tried without `--onefile`?) So, if you import webdriver from selenium in your code, yes, selenium dir should show up in dist. I found this [link](https://irwinkwan.com/2013/04/29/python-executables-pyinstaller-and-a-48-hour-game-design-compo/), maybe you should follow it in onefile case. – monami Dec 08 '16 at 21:23
  • 1
    chromedriver was being bundled, but I wasn't properly accessing its location in the app. The lines you mentioned above worked `dir = os.path.dirname(__file__) chrome_path = os.path.join(dir, 'selenium','webdriver','chromedriver.exe') service = service.Service(chrome_path)`. I just needed to access the paths with resource_path() and just passed the path into webdriver.Chrome(). You can add it as an answer if you like. – ballade4op52 Dec 12 '16 at 00:24
  • Cool, that you could solve it :) If you think my answer on the linked question helped you find your solution, and maybe this chat, too, please vote to both, thank you! – monami Dec 20 '16 at 21:06

1 Answers1

2

Yes, that was Windows path. In Unix, you need to use ./selenium/webdriver instead. It tells where to place the chromedriver binary in the bundle, so after pyinstall, chromedriver will be in /path/to/bundle/dist/selenium/webdriver.
Then in the code you should use something like this to reach it (it's a remote example):

dir = os.path.dirname(__file__)
chrome_path = os.path.join(dir, 'selenium','webdriver','chromedriver.exe')
service = service.Service(chrome_path) ... 
monami
  • 594
  • 2
  • 9
  • 32