huggingface/open-r1 · error

Required MorphCloud dependencies not installed: {e}

Error message

Required MorphCloud dependencies not installed: {e}

What it means

This ImportError wraps an ImportError raised while constructing MorphCloudClient or binding the Sandbox class inside MorphProvider.__init__. The original exception message is interpolated into `{e}`, so it means morphcloud's own internal dependencies (or a partial install) are broken even though the top-level import passed the earlier availability check.

Source

Thrown at src/open_r1/utils/code_providers.py:209

        self.num_parallel = num_parallel
        self.morph_router_url = morph_router_url

        if self.morph_router_url is not None:
            self.routed_sandbox = RoutedMorphSandbox(router_url=self.morph_router_url)
            return

        import os

        self.api_key = os.getenv("MORPH_API_KEY")
        if not self.api_key:
            raise ValueError("MorphCloud API key not found. Please set the MORPH_API_KEY environment variable.")

        try:
            self.client = MorphCloudClient(api_key=self.api_key)
            self.Sandbox = Sandbox
        except ImportError as e:
            raise ImportError(f"Required MorphCloud dependencies not installed: {e}")

    def execute_scripts(self, scripts: List[str], languages: List[str]) -> List[float]:
        """Execute scripts using MorphCloud Sandbox API.

        Args:
            scripts: List of Python scripts to execute
            language: Programming language

        Returns:
            List of float rewards (one per script)
        """

        if hasattr(self, "routed_sandbox"):
            try:
                results = self.routed_sandbox.run_code(
                    scripts=scripts,
                    languages=languages,
                    timeout=90,

View on GitHub (pinned to 1416fa0cf2)

Solutions

  1. Read the wrapped message in {e} to identify the actual missing module
  2. Reinstall cleanly: pip install --force-reinstall -U morphcloud
  3. Install any extras morphcloud documents (e.g. pip install 'morphcloud[all]')
  4. Pin/align conflicting dependency versions named in the inner error

Example fix

// before
provider = MorphProvider()  # ImportError: Required MorphCloud dependencies not installed: No module named 'morphcloud.sandbox'
// after
# shell: pip install --force-reinstall -U morphcloud
provider = MorphProvider()  # works
Defensive patterns

Strategy: try-catch

Validate before calling

def check_morph_client():
    try:
        from morphcloud.api import MorphCloudClient  # noqa: F401
    except ImportError as e:
        raise SystemExit(f"morphcloud broken install: {e}; run pip install --force-reinstall -U morphcloud") from e

Type guard

def morph_client_importable() -> bool:
    try:
        from morphcloud.api import MorphCloudClient  # noqa: F401
        return True
    except ImportError:
        return False

Try / catch

try:
    provider = MorphProvider()
except ImportError as e:
    logger.error("MorphCloud deps broken: %s", e)
    logger.error("Fix with: pip install --force-reinstall -U morphcloud")
    raise SystemExit(1) from e

Prevention

When it happens

Trigger: MorphProvider.__init__ executes `self.client = MorphCloudClient(api_key=...)` or `self.Sandbox = Sandbox` and one of those imports raises ImportError — e.g. morphcloud installed with missing extras, a broken transitive dependency, or a version whose submodule layout changed.

Common situations: Pip resolved an old/incompatible morphcloud version; a partial install after a network failure; conflicting package versions (e.g. pydantic/httpx pinned elsewhere) breaking morphcloud's imports; importing Sandbox from a submodule path that moved between versions.

Related errors


AI-assisted analysis of huggingface/open-r1@1416fa0cf2 (2026-08-30). Data as JSON: /api/errors/e9a0c85db789e742. Report an issue: GitHub.