abetlen / llama-cpp-python

Python bindings for llama.cpp
https://llama-cpp-python.readthedocs.io
MIT License
7.57k stars 909 forks source link

The compiled libllama.dll could NOT be found. #1517

Open ikionchiu opened 2 months ago

ikionchiu commented 2 months ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

Expected Behavior

Current Behavior

Environment and Context

Physical hardware i am using:

SDK version(The CMake and MinGW folders were copied from CLion and added separately to the environment variables):

Steps to Reproduce

  1. step 1: Create env folder and placed in the same directory level as llama-cpp-python.

  2. step 2: Copy the CMake and MinGW folders from CLion directory and add to the env folder.

  3. step 3: Add CMake and MinGW to the system environment variables.(cmake: ***\env\cmake\win\x64\bin; mingw:***\env\mingw\bin)

  4. step 4: cd llama-cpp-python

  5. step 5: mkdir build

  6. step 6: cd build

  7. step 7: cmake .. -DBUILD_SHARED_LIBS=ON -G "MinGW Makefiles"

  8. step 8: cmake --build . --config Release

  9. step 9: Then, I can find the libllama.dll file in the directory ***\llama-cpp-python\build\bin\.

  10. step 10: Then, I copied the generated libllama.dll to another directory for testing, but the test failed. I pinpointed the issue to the following code:

    import ctypes
    import os
    cdll_args = dict()
    cdll_args["winmode"] = ctypes.RTLD_GLOBAL
    os.add_dll_directory('D:/temp/test/llama_cpp')
    _lib_path = 'D:/temp/test/llama_cpp/libllama.dll'
    ctypes.CDLL(str(_lib_path), **cdll_args)

Failure Logs

The ERROR log as following:

Traceback (most recent call last):
  File "D:\temp\test.py", line 25, in <module>
    ctypes.CDLL(str(_lib_path), **cdll_args)
  File "C:\Users\testuser\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 127] The specified procedure could not be found
SavorSauc3 commented 1 month ago

Have you tried checking the directory that the llama_cpp is in? On linux machines the name of the .so file is libllama.so, but on windows machines where the file is a .dll, the names are llama.dll and llava.dll. You could try the following code and check if it works: _lib_path = 'D:/temp/test/llama_cpp/llama.dll'