Error while executing my .exe made with pyinstaller

Viewed 743

I made a little program that uses selenium web driver in python. My program works fine when running on spyder. Then i use pyinstaller to do the exe

pyinstaller ./main.py --onefile --noconsole --add-binary "./driver/chromedriver.exe;./driver"

But then can't launch it, I got this error

Traceback (most recent call last):
File "noto.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
File "selenium\webdriver\__init__.py", line 18, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
File "selenium\webdriver\firefox\webdriver.py", line 29, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
File "selenium\webdriver\remote\webdriver.py", line 26, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
File "selenium\webdriver\remote\webelement.py", line 43, in <module>
File "pkgutil.py", line 637, in get_data
File "PyInstaller\loader\pyimod03_importers.py", line 479, in get_data
FileNotFoundError: [Errno 2] No such file or 
directory:'C:\\Users\\Mon nom\\AppData\\Local\\Temp\\1\\_MEI50482\\
selenium\\webdriver\\remote\\getAttribute.js'
[28052] Failed to execute script 'noto' due to unhandled exception!

So indeed, I don't have this directory because selenium is installed in this path: C:\Users\Mon nom\Anaconda3\Lib\site-packages\selenium\webdriver\remote and i have the getAttribute.js file.

Does somebody have an idea ? :)

3 Answers

i used spec file

pyinstaller --clean PolyTasks.spec

the spec file is

# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_data_files

datas = []
datas += collect_data_files('selenium')


block_cipher = None


a = Analysis(['PolyTasks.py'],
             pathex=[],
             binaries=[ ( './driver/94chromedriver.exe', './driver' ) ],
             datas=datas,
             hiddenimports=[],
             hookspath=[],
             hooksconfig={},
             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, 
          [],
          exclude_binaries=True,
          name='PolyTasks',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True,
          disable_windowed_traceback=False,
          target_arch=None,
          codesign_identity=None,
          entitlements_file=None )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas, 
               strip=False,
               upx=True,
               upx_exclude=[],
               name='PolyTasks')
import shutil
shutil.copyfile('poly_ep_ring.csv', '{0}/poly_ep_ring.csv'.format(DISTPATH))

just add

--collect-data selenium

option to your pyinstaller command line,

so it should be like:

pyinstaller ./main.py  --collect-data selenium  --onefile --noconsole --add-binary "./driver/chromedriver.exe;./driver"

Try to take build with different pyinstaller version.

I faced this issue with pyinstaller 4.7

But with pyinstaller==4.3 it get resolved.

Try :

pip install pyinstaller==4.3
Related