简体   繁体   中英

Python - pyinstaller : Read path file inside script to use in pyinstaller

I have script and work fine but after executable script by pyinstaller the scripte can't able to read file chromedriver.exe:

This is the module code:

fulpath of data.py is: app\Resources\Data.py # the name app is root of script

name module data.py :

class General():

    chrome_path = "drivers\\chrome\\chromedriver.exe"

    CHROME = chrome_path

I use CHROME function in another module to run script.

Full path of chromedriver.exe is: app\drivers\chrome\chromedriver.exe # the name app is root of script.

this is the app.spec:

block_cipher = None

added_files = [
    ('driver/chrome/chromedriver.exe','driver/chrome/')
    ]

a = Analysis(['app.py'],
             pathex=['C:\\Users\\JOHN\\Desktop\\project'],
             binaries=[],
             datas=added_files,
             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='app',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True,
          uac_admin=True,
          icon='data\\image\\icon.ico')

How can I change path to compatible by pyinstaller

When you call pyinstaller to build the executable, you can use --add-data "drivers/chrome/chromedriver.exe;drivers/chrome" as a flag to add whatever you want to the build, as seen here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM