Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Module import doesn't work when using pip install llama-cpp-python --target="dir"

未关闭 适合新手
#907 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
build-system

调研方向

该 issue 位于 llama_cpp/llama.py 第 26-27 行,在使用 --target 安装时 import 会失败。检查模块结构,以了解正确的 import 路径。将 package 使用 --target 安装到临时目录中,并验证 import 能够正常工作,以测试该修复。检查代码库中是否还有其他类似的 import 语句可能需要进行相同的更改。

由索引模型根据 Issue 内容生成。

描述

bug build

When using the latest update with how I've setup my embedded install, I ran into this issue:

No module named 'llama_cpp.llama_chat_format'
Traceback (most recent call last):
  File "Z:\Anyboty_Client\llamacppClient.py", line 252, in <module>
    llama_cpp = importlib.import_module(llama_module_dir, package="llama_cpp") # Import the llama module from the llama-cpp-python module
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "Z:\Anyboty_Client\PythonFiles\llama_cpp_versions\12_1\ggufv2\windows10\llama_cpp\__init__.py", line 2, in <module>
    from .llama import *
  File "Z:\Anyboty_Client\PythonFiles\llama_cpp_versions\12_1\ggufv2\windows10\llama_cpp\llama.py", line 27, in <module>
    import llama_cpp.llama_chat_format as llama_chat_format
ModuleNotFoundError: No module named 'llama_cpp.llama_chat_format'

I resolved the issue in my specific setup by changing this:
https://github.com/abetlen/llama-cpp-python/blob/01846a76b980224609ac8b69c8eb3f5785816752/llama_cpp/llama.py#L26-L27

To this:

from . import llama_cpp
from . import llama_chat_format

And while I think this is probably a fine solution, not 100% sure. So thought I'd just bring it to y'alls attention and let you fix it properly.

主要语言
Python
星标
10.6k
派生
1.5k
平均合并
6 小时 43 分钟
30 天内合并 PR
2

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

abetlen/llama-cpp-python 的其他 Issue

查看 abetlen/llama-cpp-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。