{"record":{"id":"cb5a2cb76e1f62b9","repo":"chroma-core/chroma","slug":"the-openai-python-package-is-not-installed-please-cb5a2c","errorCode":null,"errorMessage":"The openai python package is not installed. Please install it with `pip install openai`. Note: Morph uses the OpenAI client library for API communication.","messagePattern":"The openai python package is not installed\\. Please install it with `pip install openai`\\. Note: Morph uses the OpenAI client library for API communication\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/morph_embedding_function.py","lineNumber":36,"sourceCode":"        \"\"\"\n        Initialize the MorphEmbeddingFunction.\n\n        Args:\n            api_key (str, optional): The API key for the Morph API. If not provided,\n                it will be read from the environment variable specified by api_key_env_var.\n            model_name (str, optional): The name of the model to use for embeddings.\n                Defaults to \"morph-embedding-v2\".\n            api_base (str, optional): The base URL for the Morph API.\n                Defaults to \"https://api.morphllm.com/v1\".\n            encoding_format (str, optional): The format for embeddings (float or base64).\n                Defaults to \"float\".\n            api_key_env_var (str, optional): Environment variable name that contains your API key.\n                Defaults to \"MORPH_API_KEY\".\n        \"\"\"\n        try:\n            import openai\n        except ImportError:\n            raise ValueError(\n                \"The openai python package is not installed. Please install it with `pip install openai`. \"\n                \"Note: Morph uses the OpenAI client library for API communication.\"\n            )\n\n        if api_key is not None:\n            warnings.warn(\n                \"Direct api_key configuration will not be persisted. \"\n                \"Please use environment variables via api_key_env_var for persistent storage.\",\n                DeprecationWarning,\n            )\n\n        self.api_key_env_var = api_key_env_var\n        self.api_key = api_key or os.getenv(api_key_env_var)\n        if not self.api_key:\n            raise ValueError(f\"The {api_key_env_var} environment variable is not set.\")\n\n        self.model_name = model_name\n        self.api_base = api_base","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/morph_embedding_function.py#L18-L54","documentation":"MorphEmbeddingFunction uses the OpenAI python client pointed at Morph's base URL (https://api.morphllm.com/v1), importing openai lazily in __init__. If the openai package is absent, the ImportError becomes this ValueError at construction — the message explicitly notes Morph rides on the OpenAI client library. openai is optional in chromadb installs.","triggerScenarios":"MorphEmbeddingFunction(model_name='morph-embedding-v2') in an environment that never installed openai; slim containers; envs where openai was uninstalled after another EF stopped needing it.","commonSituations":"Switching a project from a no-openai setup to the Morph EF; CI environments caching partial installs; local venvs created before Morph integration was added.","solutions":["pip install openai","Verify: python -c \"import openai; print(openai.__version__)\"","Pin openai in requirements so future syncs keep it"],"exampleFix":"# before\nfrom chromadb.utils.embedding_functions import MorphEmbeddingFunction\nef = MorphEmbeddingFunction()  # ValueError: openai missing\n\n# after\n# pip install openai\nimport importlib.util\nif importlib.util.find_spec(\"openai\") is None:\n    raise SystemExit(\"pip install openai\")\nef = MorphEmbeddingFunction()","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec(\"openai\") is None:\n    raise SystemExit(\"Morph EF rides on the OpenAI client: pip install openai\")\n\nfrom chromadb.utils.embedding_functions import MorphEmbeddingFunction\nef = MorphEmbeddingFunction()","typeGuard":null,"tryCatchPattern":"try:\n    ef = MorphEmbeddingFunction()\nexcept ValueError as e:\n    if \"openai\" in str(e):\n        raise RuntimeError(\"pip install openai\") from e\n    raise","preventionTips":["Remember Morph requires the openai package even though it is not OpenAI's API","Declare openai explicitly in requirements when enabling the Morph EF","Preflight find_spec checks per configured EF at app start"],"tags":["python","dependency","pip","openai","morph","optional-import"],"backgroundTag":"missing-optional-dependency","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}