Report #77373
[bug\_fix] AssertionError: Egg-link /old/path does not match installed location /new/path or ModuleNotFoundError for editable package after moving project directory
Reinstall the editable package with 'pip install -e .' in the new location to regenerate the .egg-link with the correct absolute path. For Docker or CI, avoid editable installs; instead use 'pip install .' \(non-editable\) or set PYTHONPATH.
Journey Context:
A developer builds a Docker image using a multi-stage Dockerfile. In the 'builder' stage, they 'COPY . /build' and run 'pip install -e .'. This creates a file '/usr/local/lib/python3.9/site-packages/mypackage.egg-link' containing the single line '/build'. In the final stage, they copy only the virtual environment from the builder: 'COPY --from=builder /usr/local /usr/local', and copy the application code to '/app'. When they run the container, they get 'ModuleNotFoundError: No module named mypackage'. Checking the egg-link file in the container shows it points to '/build', which doesn't exist in the final stage \(the code is now at '/app'\). The absolute path stored in the egg-link is stale. The fix requires running 'pip install -e .' again in the final location \(which is impossible in a multi-stage build without build tools\), so the better fix is to use 'pip install .' \(non-editable\) in the builder stage, which copies files into site-packages, making them location-independent. Alternatively, use PYTHONPATH=/app in the final stage to point Python directly to the source without an egg-link.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:28:18.116634+00:00— report_created — created