Windows: every failed `import llama_cpp` prepends to PATH and adds DLL directories again
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Empieza en llama_cpp/_ctypes_extensions.py y sigue load_shared_library, especialmente las llamadas de Windows a os.add_dll_directory y las actualizaciones de PATH antes de cargar con CDLL. Reproduce el problema con importaciones fallidas repetidas en Windows y comprueba cómo se gestionan los identificadores de directorio DLL cuando se produce una excepción durante la carga. Se considera terminado cuando los intentos fallidos dejan PATH y los directorios de búsqueda de DLL sin cambios o evitan añadir entradas duplicadas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
On Windows, load_shared_library in llama_cpp/_ctypes_extensions.py changes process state before it knows the library will load:
if sys.platform == "win32":
os.add_dll_directory(str(base_path))
os.environ["PATH"] = str(base_path) + os.pathsep + os.environ["PATH"]
if sys.platform == "win32" and sys.version_info >= (3, 8):
os.add_dll_directory(str(base_path))
if "CUDA_PATH" in os.environ:
os.add_dll_directory(os.path.join(os.environ["CUDA_PATH"], "bin"))
os.add_dll_directory(os.path.join(os.environ["CUDA_PATH"], "lib"))
If llama.dll then fails to load, the import raises and Python does not cache the module. The next import llama_cpp runs all of this again. Each failed attempt adds one more PATH entry and four more DLL directories, and none of them are removed.
That matters for long-running apps that check whether llama.cpp is available, for example on a status poll. In our case the app retried the import from a status check. After about three hours the process PATH held the same llama_cpp\lib entry 104 times (12,323 characters). Then an unrelated library failed at its own os.add_dll_directory call with [WinError 206] The filename or extension is too long.
Reproduce
Use any install where llama.dll cannot load. A CUDA 12 wheel on a machine with only CUDA 13 installed does it:
import os
for _ in range(3):
try:
import llama_cpp
except RuntimeError as error:
print(type(error).__name__)
print(os.environ["PATH"].count("llama_cpp")) # prints 3, expected 1
Expected
A failed load leaves PATH and the DLL search list as they were, or adds each entry at most once per process.
Possible fix
- Keep the handles that
os.add_dll_directoryreturns, and close them when theCDLLcall fails. - Prepend to PATH only if the entry is not already there.
base_pathis added twice on Python 3.8 and later. One call is enough.
Environment
- llama-cpp-python 0.3.37 (CUDA wheel, built against cublas64_12 and cudart64_12)
- Windows 11, Python 3.12
CUDA_PATHpoints to CUDA 13.1
- Lenguaje dominante
- Python
- Estrellas
- 10.7k
- Forks
- 1.5k
- Merge medio
- 1 h 40 min
- PR fusionados (30 d)
- 5
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de abetlen/llama-cpp-python
-
Seven llama_sampler_init_* bindings admit keyword arguments that the ctypes function object silently dropsPosiblemente ocupada @Belal0066 la tomó hace 59 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
abetlen/llama-cpp-python#2371 ·
Los mantenedores suelen responder en 1 día
-
uv add llama-cpp-python wheels fails for versions above 0.3.30Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
abetlen/llama-cpp-python#2352 · 1 comentario · 3 reacciones ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
abetlen/llama-cpp-python#2314 ·
Los mantenedores suelen responder en 1 día
-
Llama.embed() calls LlamaBatch.add_sequence with old 3-arg signature; missing logits_arrayQuizá libre de nuevo @lxcxjxhx la tomó hace 136 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
abetlen/llama-cpp-python#2211 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Llama() silently accepts and discards `embedding` kwarg; .embed() then raises confusinglyPosiblemente ocupada @Anai-Guo la tomó hace 76 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
abetlen/llama-cpp-python#2210 ·
Los mantenedores suelen responder en 1 día
Todos los issues de abetlen/llama-cpp-python
Issues similares
-
Bug IronPython Python 3
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
pyrevitlabs/pyRevit#4184 ·
Los mantenedores suelen responder en 1 día
-
CLAW (Agents & Orchestration)Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 74/100
jqueryscript/awesome-claude-code#1009 ·
-
tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
[Plugin] 群聊记忆 · 人格养成Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 74/100