{"record":{"id":"a0c659e815f5ed26","repo":"crewAIInc/crewAI","slug":"could-not-import-langchain-apify-python-package-p","errorCode":null,"errorMessage":"Could not import langchain_apify python package. Please install it with `pip install langchain-apify` or `uv add langchain-apify`.","messagePattern":"Could not import langchain_apify python package\\. Please install it with `pip install langchain-apify` or `uv add langchain-apify`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/apify_actors_tool/apify_actors_tool.py","lineNumber":69,"sourceCode":"                print(f\"URL: {result['metadata']['url']}\")\n                print(f\"Content: {result.get('markdown', 'N/A')[:100]}...\")\n    \"\"\"\n    actor_tool: _ApifyActorsTool = Field(description=\"Apify Actor Tool\")\n    package_dependencies: list[str] = Field(default_factory=lambda: [\"langchain-apify\"])\n\n    def __init__(self, actor_name: str, *args: Any, **kwargs: Any) -> None:\n        if not os.environ.get(\"APIFY_API_TOKEN\"):\n            msg = (\n                \"APIFY_API_TOKEN environment variable is not set. \"\n                \"Please set it to your API key, to learn how to get it, \"\n                \"see https://docs.apify.com/platform/integrations/api\"\n            )\n            raise ValueError(msg)\n\n        try:\n            from langchain_apify import ApifyActorsTool as _ApifyActorsTool\n        except ImportError as e:\n            raise ImportError(\n                \"Could not import langchain_apify python package. \"\n                \"Please install it with `pip install langchain-apify` or `uv add langchain-apify`.\"\n            ) from e\n        actor_tool = _ApifyActorsTool(actor_name)\n\n        kwargs.update(\n            {\n                \"name\": actor_tool.name,\n                \"description\": actor_tool.description,\n                \"args_schema\": actor_tool.args_schema,\n                \"actor_tool\": actor_tool,\n            }\n        )\n        super().__init__(*args, **kwargs)\n\n    def _run(self, run_input: dict[str, Any]) -> list[dict[str, Any]]:\n        \"\"\"Run the Actor tool with the given input.\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/apify_actors_tool/apify_actors_tool.py#L51-L87","documentation":"ApifyActorsTool wraps langchain-apify's ApifyActorsTool as an optional dependency; after the token check it tries `from langchain_apify import ApifyActorsTool` and on ImportError re-raises with install instructions. The package is not installed with crewai-tools by default.","triggerScenarios":"Constructing ApifyActorsTool in an environment lacking langchain-apify; installing it into a different venv/interpreter than the one running CrewAI; a broken partial install where the import raises ImportError.","commonSituations":"Fresh environment without extras; lockfile missing the optional package; system vs project Python mismatch; CI cache without the wheel.","solutions":["Install it: `pip install langchain-apify` (or `uv add langchain-apify`).","Confirm the import works in the running interpreter: `python -c \"from langchain_apify import ApifyActorsTool\"`.","Add it to project dependencies so environments are reproducible."],"exampleFix":"# before\ntool = ApifyActorsTool(\"my-actor\")  # ImportError\n\n# after (shell first)\n# pip install langchain-apify\ntool = ApifyActorsTool(\"my-actor\")","handlingStrategy":"fallback","validationCode":"def langchain_apify_available() -> bool:\n    try:\n        from langchain_apify import ApifyActorsTool  # noqa: F401,F401\n        return True\n    except ImportError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    tool = ApifyActorsTool(\"my-actor\")\nexcept ImportError as e:\n    if \"langchain_apify\" in str(e):\n        raise SystemExit(\"Run: pip install langchain-apify\") from e\n    raise","preventionTips":["Declare optional integrations (langchain-apify) in project dependencies up front.","Probe availability before building crews that include the tool so failure is actionable.","Install into the venv the app runs from; check `which python` when imports surprise you."],"tags":["dependencies","import-error","installation","apify"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}