[GH-ISSUE #2185] Python example does not work #1248

Closed
opened 2026-04-12 11:01:20 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @claremont-awilson on GitHub (Jan 25, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/2185

Reading this: https://ollama.ai/blog/python-javascript-libraries

Trying to perform the Python example errors on macOS and OEL9:

import ollama
response = ollama.chat(
    model="llama2",
    messages=[
        {
            "role": "user",
            "content": "Why is the sky blue?",
        },
    ],
)
print(response["message"]["content"])

error is:

Traceback (most recent call last):
File "/home/my_name/repos/Python/ollama.py", line 1, in
import ollama
File "/home/my_name/repos/Python/ollama.py", line 3, in
response = ollama.chat(
AttributeError: partially initialized module 'ollama' has no attribute 'chat' (most likely due to a circular import)

Python version: 3.9.18

Originally created by @claremont-awilson on GitHub (Jan 25, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/2185 Reading this: https://ollama.ai/blog/python-javascript-libraries Trying to perform the Python example errors on macOS and OEL9: ```python import ollama response = ollama.chat( model="llama2", messages=[ { "role": "user", "content": "Why is the sky blue?", }, ], ) print(response["message"]["content"]) ``` error is: > Traceback (most recent call last): > File "/home/my_name/repos/Python/ollama.py", line 1, in <module> > import ollama > File "/home/my_name/repos/Python/ollama.py", line 3, in <module> > response = ollama.chat( > AttributeError: partially initialized module 'ollama' has no attribute 'chat' (most likely due to a circular import) Python version: 3.9.18
Author
Owner

@jmorganca commented on GitHub (Jan 25, 2024):

Ah! This may be because you named your python file ollama.py, and so it's creating a circular import. Try naming it example.py for example. Funny enough I did this too when trying to reproduce this issue before realizing 😊

<!-- gh-comment-id:1909829740 --> @jmorganca commented on GitHub (Jan 25, 2024): Ah! This may be because you named your python file `ollama.py`, and so it's creating a circular import. Try naming it `example.py` for example. Funny enough I did this too when trying to reproduce this issue before realizing 😊
Author
Owner

@TiniKrasniqi commented on GitHub (Nov 7, 2024):

Ah! This may be because you named your python file ollama.py, and so it's creating a circular import. Try naming it example.py for example. Funny enough I did this too when trying to reproduce this issue before realizing 😊

Had the same problem and this was the problem, thanks.

<!-- gh-comment-id:2461820011 --> @TiniKrasniqi commented on GitHub (Nov 7, 2024): > Ah! This may be because you named your python file `ollama.py`, and so it's creating a circular import. Try naming it `example.py` for example. Funny enough I did this too when trying to reproduce this issue before realizing 😊 Had the same problem and this was the problem, thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#1248