Introduction

This article outlines the process of setting up the Lean engine for Python on macOS, utilizing Visual Studio Code (VSCode). If you encounter issues with port availability, this guide will help you troubleshoot and resolve them.

Prerequisites

Ensure you have Docker installed and running on your macOS system. You can verify this by running docker --version in your terminal.

Configuration Steps

  1. Clone the Lean Repository: Start by cloning the Lean repository from GitHub:

    git clone https://github.com/QuantConnect/Lean.git
    cd Lean
  2. Open VSCode: Launch Visual Studio Code and open the cloned Lean directory.

  3. Run the Lean Engine: To initiate the Lean engine, execute the following command in your terminal:

    docker run --rm \
        --mount type=bind,source=$(pwd)/Launcher/config.json,target=/Lean/Launcher/config.json,readonly \
        -v $(pwd)/Data:/Data:ro \
        -v $(pwd)/Results:/Results \
        --name LeanEngine \
        -p 5678:5678 \
        --expose 6000 \
        -v $(pwd)/Algorithm.Python:/Lean/Algorithm.Python \
        quantconnect/lean:latest --data-folder /Data --results-destination-folder /Results --config /Lean/Launcher/config.json
  4. Debugging Issues: If you encounter an error like:

    docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:55555: bind: address already in use.

    This indicates that the port 55555 is already in use. You can check which process is using the port by running:

    sudo lsof -i:55555

    If no processes are listed, the issue may stem from the debugging options set in your configuration.

  5. Adjust Debugging Settings: If debugging is enabled and causing the port conflict, try disabling it. You can run the Lean engine without the debugging options:

    docker run --rm \
        --mount type=bind,source=$(pwd)/Launcher/config.json,target=/Lean/Launcher/config.json,readonly \
        -v $(pwd)/Data:/Data:ro \
        -v $(pwd)/Results:/Results \
        --name LeanEngine \
        -p 5678:5678 \
        --expose 6000 \
        -v $(pwd)/Algorithm.Python:/Lean/Algorithm.Python \
        quantconnect/lean:latest --data-folder /Data --results-destination-folder /Results --config /Lean/Launcher/config.json

Conclusion

By following these steps, you should be able to set up the Lean engine on your macOS system. If you continue to experience issues, consider checking your Docker settings or consulting the QuantConnect community for further assistance.