1

I created app to just open browser like following code and it works fine from cmd line.
But, when I packaged it by pyinstaller, it doesn't work..

What's the problem? I will appreciate your help with this situation.

# main.py
# -*- coding: utf-8 -*-
import os

from selenium import webdriver

if __name__ == '__main__':
    PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
    DRIVER_BIN = os.path.join(PROJECT_ROOT, "chromedriver")

    browser = webdriver.Chrome(executable_path=DRIVER_BIN)
    browser.get('https://google.com/')

This is .spec file.

# -*- mode: python -*-
import os

project_path = os.path.abspath(os.path.curdir)

block_cipher = None

a = Analysis(['main.py'],
             pathex=[project_path],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='test',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=False)

app = BUNDLE(exe,
         name='test.app',
         icon=None,
         bundle_identifier=None)

And file tree is like these.

dist/  
      test.app  
      test  
      chromedriver <- add after packaged

error is maybe this.

Jun 26 14:42:01 MacBookPro ctkahp[67399]: objc[67399]: Class TKTokenRefCtkd is implemented in both /System/Library/Frameworks/Security.framework/Versions/A/Sec    urity (0x7fff8a3cf0a0) and /System/Library/Frameworks/CryptoTokenKit.framework/ctkahp.bundle/Contents/MacOS/ctkahp (0x10ecbc760). One of the two will be used.     Which one is undefined.
Jun 26 14:42:16 MacBookPro com.apple.xpc.launchd[1] (highlow.23356[67408]): Service exited with abnormal code: 255
naohide_a
  • 1,116
  • 2
  • 13
  • 30
  • Is there an error? – orde Jun 26 '19 at 07:00
  • @orde maybe, these? Jun 26 14:42:01 MacBookPro ctkahp[67399]: objc[67399]: Class TKTokenRefCtkd is implemented in both /System/Library/Frameworks/Security.framework/Versions/A/Sec urity (0x7fff8a3cf0a0) and /System/Library/Frameworks/CryptoTokenKit.framework/ctkahp.bundle/Contents/MacOS/ctkahp (0x10ecbc760). One of the two will be used. Which one is undefined. 752 Jun 26 14:42:16 MacBookPro com.apple.xpc.launchd[1] (highlow.23356[67408]): Service exited with abnormal code: 255 – naohide_a Jun 26 '19 at 07:06

2 Answers2

0

I found the solution.
I tried to set full path into executable_path. And then it works fine.

But I can't understand why this is problem.

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
DRIVER_BIN = os.path.join(PROJECT_ROOT, "chromedriver")

browser = webdriver.Chrome(executable_path=DRIVER_BIN)

And also this.

browser = webdriver.Chrome(executable_path="./chromedriver")

Where does .app file look at?

naohide_a
  • 1,116
  • 2
  • 13
  • 30
0

The path of test script executed by command differs from the "bundle".

You could try this
main.py

import os
import sys

if __name__ == "__main__":
  if getattr(sys, 'frozen', False): 
    chromedriver_path = os.path.join(sys._MEIPASS, "chromedriver")
    driver = webdriver.Chrome(chromedriver_path)
  else:
    driver = webdriver.Chrome()

main.spec

project_path = os.path.abspath(os.path.curdir)
a = Analysis(['main.py'],
             pathex=[project_path],
             binaries=[('/Users/xxx/xxx/chromedriver', './')],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

(ref.: https://github.com/pyinstaller/pyinstaller/issues/1726)
(ref.: Running pyinstaller another pc with Chromedriver)

eee
  • 781
  • 5
  • 8