[Python] llama-cpp and transformers with pyinstaller in creation of .exe file

Discussão em 'Python' iniciado por Stack, Maio 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am attempting to bundle a rag agent into a .exe. However on usage of the .exe i keep running into the same two problems. The first initial problem is with locating llama-cpp, which i have fixed. The second is a recurring error, which i am unable to solve with any resources i've found on existing queries and gpt responses.

    FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\caio\\AppData\\Local\\Temp\\_MEI43162\\transformers\\models\\__init__.pyc'
    [PYI-2444:ERROR] Failed to execute script 'frontend' due to unhandled exception!


    I looked into my path, and found no init.pyc but a init.py I have attempted to solve this by

    1. Modifying the spec file (hasn't worked)

    # -*- mode: python ; coding: utf-8 -*-

    from PyInstaller.utils.hooks import collect_submodules, collect_data_files
    import os
    import transformers
    import sentence_transformers

    hiddenimports = collect_submodules('transformers') + collect_submodules('sentence_transformers')
    datas = collect_data_files('transformers') + collect_data_files('sentence_transformers')

    a = Analysis(
    ['frontend.py'],
    pathex=[],
    binaries=[('C:/Users/caio/miniconda3/envs/rag_new_env/Lib/site-packages/llama_cpp/lib/llama.dll', 'llama_cpp/lib')],
    datas=datas,
    hiddenimports=hiddenimports,
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
    )

    pyz = PYZ(a.pure)

    exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.datas,
    [],
    name='frontend',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    )

    1. Using specific pyinstaller commands that had worked on my previous system. Hasn't worked.

    pyinstaller --onefile --add-binary "C:/Users/caio/miniconda3/envs/rag_new_env/Lib/site-packages/llama_cpp/lib/llama.dll;llama_cpp/lib" rag_gui.py


    Both attempts that I have provided fixed my llama_cpp problem but couldn't solve the transformers model. the path is as so:

    C:/Users/caio/miniconda3/envs/rag_new_env/Lib/site-packages


    Please help me on how to solve this. My transformers use is happening only through sentence_transformers.

    Continue reading...

Compartilhe esta Página