abetlen / llama-cpp-python

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

[WinError 87] The parameter is incorrect : {'winmode': 0} after upgrading from 0.2.23 to 0.2.25 #1049

Open laelhalawani opened 11 months ago

laelhalawani commented 11 months ago

Expected Behavior

I was trying to just install and use llama-cpp-python on a freshly set up anaconda environment. I updated my anaconda navigator to the 2023.09 release version. I created a new environment with python 3.11.5 I installed llama-cpp-python using pip install llama-cpp-python I tried to run

from llama_cpp import Llama, LlamaTokenizer

I expected it would import the classes into my script.

Current Behavior

It resulted in an error [WinError87] unable to load the DLL. I got an error:

C:/Users/username/Anaconda3/envs/project_env/python.exe c:/Users/username/Desktop/python/project/test.py
LLAMA_CPP_LIB NOT IN OS ENVIRON Loading shared library from: [WindowsPath('C:/Users/username/Anaconda3/envs/project_env/Lib/site-packages/llama_cpp/llama.dll'), WindowsPath('C:/Users/username/Anaconda3/envs/project_env/Lib/site-packages/llama_cpp/libllama.dll')]
Added C:\Users\username\Anaconda3\envs\project_env\Lib\site-packages\llama_cpp to DLL search path
cdll_args: {'winmode': 0}
Traceback (most recent call last):
  File "C:\Users\username\Anaconda3\envs\project_env\Lib\site-packages\llama_cpp\llama_cpp.py", line 80, in _load_shared_library
    return ctypes.CDLL(str(_lib_path), **cdll_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Anaconda3\envs\project_env\Lib\ctypes\__init__.py", line 376, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 87] The parameter is incorrect

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\username\Desktop\python\project\test.py", line 2, in <module>
    from ai import LlamaAI
  File "c:\Users\username\Desktop\python\project\ai.py", line 1, in <module>
    from llama_cpp import Llama, LlamaTokenizer
  File "C:\Users\username\Anaconda3\envs\project_env\Lib\site-packages\llama_cpp\__init__.py", line 1, in <module>
    from .llama_cpp import *
  File "C:\Users\username\Anaconda3\envs\project_env\Lib\site-packages\llama_cpp\llama_cpp.py", line 93, in <module>
    _lib = _load_shared_library(_lib_base_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Anaconda3\envs\project_env\Lib\site-packages\llama_cpp\llama_cpp.py", line 82, in _load_shared_library
    raise RuntimeError(f"Failed to load shared library '{_lib_path}': {e} : {cdll_args}")
RuntimeError: Failed to load shared library 'C:\Users\username\Anaconda3\envs\project_env\Lib\site-packages\llama_cpp\llama.dll': [WinError 87] The parameter is incorrect : {'winmode': 0}

Environment and Context

Win 11 Enterprise 10.0 22621, Anaconda Navigator 2023.09.0, Python 3.11.5, llama-ccp-python 0.2.25

It's worth noting that before Anaconda upgrade I was never able to install this package via pip install llama-cpp-python and instead had to use git+https method. After I encountered the error I uninstalled with pip uninstall llama-cpp-python and use git+https method to reinstall but it did not help. My previous environments that use 0.2.23 version of llama-cpp-python still work correctly also with the updated Anaconda Navigator, so I doubt there's a problem with the Anaconda.

Steps to Reproduce

Described in what i've done

Side note

Thank you so much for your work and this amazing project!

abetlen commented 10 months ago

@laelhalawani sorry for the late reply, can you try cloning from the github and changing winmode in llama/llama_cpp.py and llama/llava_cpp.py to either of the values mentioned here https://stackoverflow.com/a/60723592 and letting me know if that works?