A
A
Andrew2017-09-17 23:07:22
PhantomJS
Andrew, 2017-09-17 23:07:22

How to add phantomJS to .exe via pyinstaller python?

You need to "include" PhantomJs in the .exe file.
I generate through pyinstaller .spec a file for a script.
Then I add Tree('phantomjs\\bin') there

# -*- mode: python -*-

block_cipher = None


a = Analysis(['test_phantom.py'],
             pathex=['D:\\python35_64'],
             binaries=[],
             datas=[],
             hiddenimports=['queue'],
             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,
      Tree('phantomjs\\bin'),
          a.zipfiles,
          a.datas,
          name='test_phantom',
          debug=False,
          strip=False,
          upx=True,
          console=True )

In the script itself, the call goes like this:
browser = webdriver.PhantomJS(('phantomjs\\bin\\phantomjs.exe'))

How to correctly write the path in the script and in the .spec file so that the .exe file runs without problems on other PCs? Without additional installation of a phantom and prescribing in Path.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2017-10-22
@prolisk

If done through pyinstaller, then in the .py script the following code:

try:
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")        
    browser = webdriver.PhantomJS(base_path+'\\phantomjs.exe')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question