Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open Beginner friendly
#907 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
build-system

Research direction

The issue is in llama_cpp/llama.py lines 26-27, where an import fails when installing with --target. Examine the module structure to understand the correct import path. Test the fix by installing the package with --target into a temporary directory and verifying the import works. Check if there are other similar import statements in the codebase that might need the same change.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
10.6k
Forks
1.5k
Avg merge
6h 43m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from abetlen/llama-cpp-python

All issues in abetlen/llama-cpp-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.