llama-cpp-python icon indicating copy to clipboard operation
llama-cpp-python copied to clipboard

Pyinstaller Cannot Find File After Compiling

Open SavorSauc3 opened this issue 1 year ago • 4 comments

Prerequisites

  • I am running the latest code. Development is very rapid so there are no tagged versions as of now.
  • I carefully followed the README.md.
  • I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed). -I reviewed the Discussions, and have a new bug or useful enhancement to share.

Expected Behavior

I am confident that llama-cpp-python shouldn't act like this after being converted to an executable. I expect the file to properly locate the necessary files after the executable is run.

Current Behavior

After compiling my FastAPI backend to an executable (uses llama-cpp-python as a dependency) I try to run the executable, I am met with the following error: Traceback (most recent call last): File "main.py", line 12, in File "", line 1360, in _find_and_load File "", line 1331, in _find_and_load_unlocked File "", line 935, in load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module File "llama_cpp_init.py", line 1, in File "", line 1360, in _find_and_load File "", line 1331, in _find_and_load_unlocked File "", line 935, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module File "llama_cpp\llama_cpp.py", line 83, in File "llama_cpp\llama_cpp.py", line 57, in _load_shared_library File "", line 1125, in add_dll_directory FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\Users\NATHAN~1\AppData\Local\Temp\_MEI253282\llama_cpp' [23408] Failed to execute script 'main' due to unhandled exception!

In the first place, there is no AppData directory on my machine, and there is no NATHAN~1 user on my machine.

Environment and Context

I am using an Anaconda environment on Windows, I don't think that the other dependencies are causing this bug, it's probably got something to do with how the python bindings load the llama_cpp dependency, which is loaded on installation of the module.

  • Physical Windows 11
$ python3 --version
3.12.3

Steps to Reproduce

Please provide detailed steps for reproducing the issue. We are not sitting in front of your screen, so the more detail the better.

  1. Create a python file that uses llama-cpp-python
  2. Convert the python file to an executable with pyinstaller example.py
  3. Run the executable in the dist folder

SavorSauc3 avatar Jun 30 '24 22:06 SavorSauc3

Have you found any solution for this?

zarko379 avatar Sep 23 '24 21:09 zarko379

+1

Enternalcode avatar Oct 14 '24 08:10 Enternalcode

+1

Vinttri avatar Nov 15 '24 07:11 Vinttri

for future users https://github.com/abetlen/llama-cpp-python/pull/709/files

dejwi avatar Feb 14 '25 02:02 dejwi