Skip to content

Conversation

@zeke
Copy link
Member

@zeke zeke commented Aug 22, 2025

This PR is an attempt to fix a ModuleNotFoundError when importing the replicate library by adding the missing packaging dependency to pyproject.toml.

Not sure if this is the right way to add this dep. @dgellow I could use your guidance here!

Problem

The replicate.lib._schema module imports packaging.version but the packaging library wasn't declared as a dependency, causing runtime errors:

ModuleNotFoundError: No module named 'packaging'

Original error

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/local/lib/python3.13/site-packages/coglet/schema.py", line 53, in <module>
    main()
    ~~~~^^
  File "/usr/local/lib/python3.13/site-packages/coglet/schema.py", line 44, in main
    raise e
  File "/usr/local/lib/python3.13/site-packages/coglet/schema.py", line 31, in main
    p = inspector.create_predictor(sys.argv[1], sys.argv[2], inspect_ast=True)
  File "/usr/local/lib/python3.13/site-packages/coglet/inspector.py", line 356, in create_predictor
    module = importlib.import_module(module_name)
  File "/usr/local/lib/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/src/main.py", line 5, in <module>
    import replicate
  File "/usr/local/lib/python3.13/site-packages/replicate/__init__.py", line 11, in <module>
    from ._client import (
    ...<9 lines>...
    )
  File "/usr/local/lib/python3.13/site-packages/replicate/_client.py", line 25, in <module>
    from replicate.lib._predictions_run import Model, Version, ModelVersionIdentifier
  File "/usr/local/lib/python3.13/site-packages/replicate/lib/_predictions_run.py", line 9, in <module>
    from replicate.lib._schema import make_schema_backwards_compatible
  File "/usr/local/lib/python3.13/site-packages/replicate/lib/_schema.py", line 3, in <module>
    from packaging import version
ModuleNotFoundError: No module named 'packaging'

The replicate.lib._schema module imports the packaging library
but it wasn't listed as a dependency in pyproject.toml, causing
ModuleNotFoundError when the module is imported.

Fixes import error: "ModuleNotFoundError: No module named 'packaging'"
@zeke zeke requested a review from a team as a code owner August 22, 2025 16:16
@zeke zeke requested a review from dgellow August 22, 2025 16:19
Copy link
Collaborator

@dgellow dgellow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

I would recommend to run uv sync locally to update the uv.lock lockfile before merging

by running `uv sync`
@zeke zeke merged commit 8c698f1 into main Aug 25, 2025
9 of 10 checks passed
@zeke zeke deleted the fix/add-packaging-dependency branch August 25, 2025 16:17
@stainless-app stainless-app bot mentioned this pull request Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants