Skip to content

Error on importing: "re.PatternError: global flags not at the start of the expression at position 24" #531

@asweigart

Description

@asweigart

I'm running ollama 0.9.0 and ollama-python 0.5.1 on Python 3.13.3 on macOS Sequoia 15.5. I get this error when I try to import the module:

>>> from ollama import chat
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    from ollama import chat
  File "/Users/al/Scripts/.venv/lib/python3.13/site-packages/ollama/__init__.py", line 1, in <module>
    from ollama._client import AsyncClient, Client
  File "/Users/al/Scripts/.venv/lib/python3.13/site-packages/ollama/_client.py", line 42, in <module>
    import httpx
  File "/Users/al/Scripts/.venv/lib/python3.13/site-packages/httpx/__init__.py", line 15, in <module>
    from ._main import main
  File "/Users/al/Scripts/.venv/lib/python3.13/site-packages/httpx/_main.py", line 9, in <module>
    import pygments.lexers
  File "/Users/al/Scripts/.venv/lib/python3.13/site-packages/pygments/__init__.py", line 37, in <module>
    from pygments.util import StringIO, BytesIO
  File "/Users/al/Scripts/.venv/lib/python3.13/site-packages/pygments/util.py", line 27, in <module>
    tag_re = re.compile(r'<(.+?)(\s.*?)?>.*?</.+?>(?uism)')
  File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/re/__init__.py", line 289, in compile
    return _compile(pattern, flags)
  File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/re/__init__.py", line 350, in _compile
    p = _compiler.compile(pattern, flags)
  File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/re/_compiler.py", line 748, in compile
    p = _parser.parse(p, flags)
  File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/re/_parser.py", line 980, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/re/_parser.py", line 459, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
                ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                       not nested and not items))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/re/_parser.py", line 841, in _parse
    raise source.error('global flags not at the start '
                       'of the expression',
                       source.tell() - start)
re.PatternError: global flags not at the start of the expression at position 24

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions