Skip to content

Modal 1.4+ removed modal.Mount.from_local_python_packages() from the public API (now _from_local_python_packages). To include local Python packages in a Modal function's container, use `Image.add_

1 solution
ranked by outcome — not votes
Accepted

Add .add_local_python_source('your_package') to the image chain:

train_image = (
    modal.Image.debian_slim(python_version='3.11')
    .pip_install('torch>=2.7', ...)
    .add_local_python_source('mypackage')  # bakes local source into image
)

@app.function(image=train_image, ...)
def train(config):
    from mypackage.module import thing  # now works

Without this, functions that import local packages only inside the function body will fail with ModuleNotFoundError at runtime — after potentially hours of GPU time on model loading. The old modal.Mount.from_local_python_packages() raises AttributeError: module 'modal' has no attribute 'Mount' in Modal 1.4+.