huggingface/open-r1 · error
MorphCloud is not available and required for this provider.
Error message
MorphCloud is not available and required for this provider. Please install MorphCloud with `pip install morphcloud` and add an API key to a `.env` file.
What it means
MorphProvider's __init__ raises ImportError when the morphcloud package is not importable. Like the E2B provider, it validates availability up front because remote sandbox execution is impossible without the SDK. It also expects a .env file with the MorphCloud API key for the later client setup.
Source
Thrown at src/open_r1/utils/code_providers.py:180
finally:
try:
await sandbox.kill()
except Exception as e:
print(f"Error from E2B executor kill with sandbox ID {sandbox.sandbox_id} : {e}")
class MorphProvider(CodeExecutionProvider):
"""Provider that executes code using MorphCloud's Sandbox API."""
def __init__(self, num_parallel: int = 2, morph_router_url: Optional[str] = None):
"""Initialize the Morph provider.
Args:
num_parallel: Number of parallel executions to use
morph_router_url: URL for the MorphCloud router (if using router mode)
"""
if not is_morph_available():
raise ImportError(
"MorphCloud is not available and required for this provider. Please install MorphCloud with "
"`pip install morphcloud` and add an API key to a `.env` file."
)
try:
from dotenv import load_dotenv
load_dotenv()
except ImportError:
print("Warning: python-dotenv not installed. Environment variables must be set directly.")
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
View on GitHub (pinned to 1416fa0cf2)
Solutions
- Install the SDK: pip install morphcloud
- Add MORPH_API_KEY to a .env file in the run's working directory (checked immediately after this guard)
- Confirm availability in the same interpreter: python -c "import morphcloud"
- Choose a different provider_type in get_provider if MorphCloud isn't intended
Example fix
// before provider = get_provider(code_provider="morph") # ImportError // after # shell: pip install morphcloud && echo 'MORPH_API_KEY=...' >> .env provider = get_provider(code_provider="morph")
Defensive patterns
Strategy: validation
Validate before calling
def require_morph():
try:
import morphcloud # noqa: F401
except ImportError as e:
raise SystemExit("Install morphcloud: pip install morphcloud") from e
import os
if not os.getenv("MORPH_API_KEY"):
# .env is loaded by the provider; check file too
try:
with open(".env") as f:
assert any(l.startswith("MORPH_API_KEY=") for l in f)
except (FileNotFoundError, AssertionError):
raise SystemExit("Set MORPH_API_KEY in .env or environment") Type guard
def is_morph_ready() -> bool:
try:
import morphcloud # noqa: F401
return True
except ImportError:
return False Try / catch
try:
provider = MorphProvider(num_parallel=4)
except ImportError as e:
logger.error("MorphCloud missing: %s — run pip install morphcloud", e)
raise SystemExit(1) from e Prevention
- Add morphcloud to the environment used by SLURM/Docker training images
- Verify the import in the exact interpreter that runs the job
- Keep a .env template (.env.example) listing MORPH_API_KEY
- Fail fast with a preflight check before multi-hour jobs
When it happens
Trigger: Instantiating MorphProvider (directly or through get_provider with a morph provider_type) while is_morph_available() returns False, i.e. the morphcloud import fails in the current interpreter.
Common situations: Deploying to a cluster node without the morphcloud extra installed; running in Docker where only base requirements were installed; using a different virtualenv than the one where morphcloud was pip-installed.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- E2B is not available and required for this provider. Please
- Required MorphCloud dependencies not installed: {e}
- Either `dataset_name` or `dataset_mixture` must be provided
- dataset_mixture must be a dictionary with a 'datasets' key.
- 'datasets' must be a list of dataset configurations
AI-assisted analysis of huggingface/open-r1@1416fa0cf2 (2026-08-30).
Data as JSON: /api/errors/657d114540e17064.
Report an issue: GitHub.