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_local_python_source('package_name') on the image definition instead. The auto-mount only triggers when Modal detects a module-level import of the local package during modal deploy — imports inside function bodies are not detected.
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 worksWithout 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+.