ModuleNotFoundError: No Module Named ‘anthropic’ (2026)

Anthropic is the official Python SDK for Claude. If your script raises ModuleNotFoundError: No module named ‘anthropic’, install it with one pip command. Make sure your environment also has the ANTHROPIC_API_KEY environment variable set.

ModuleNotFoundError No Module Named 'anthropic' (2026)

Step 1: Install the SDK

pip install anthropic

# Or with bedrock support (AWS hosted Claude):
pip install 'anthropic[bedrock]'

# With vertex (Google Cloud hosted Claude):
pip install 'anthropic[vertex]'

Step 2: Set your API key

# Linux / macOS
export ANTHROPIC_API_KEY="sk-ant-..."

# Windows PowerShell
$env:ANTHROPIC_API_KEY = "sk-ant-..."

# Or in Python (less secure, do not commit):
import os
os.environ['ANTHROPIC_API_KEY'] = 'sk-ant-...'

Step 3: First request

from anthropic import Anthropic

client = Anthropic()  # reads ANTHROPIC_API_KEY from env

message = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello, Claude!"}]
)
print(message.content[0].text)

Step 4: Streaming response

with client.messages.stream(
    model="claude-opus-4-7",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku"}]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Why this error happens

CauseFix
Package not installedpip install anthropic
Installed pip but using pip3python -m pip install anthropic
Wrong virtualenvActivate target venv then reinstall
Confused with anthropic-bedrock (old)Use main anthropic package with [bedrock] extra

Frequently Asked Questions

How do I get an Anthropic API key?

Sign up at console.anthropic.com. Add billing details. Create an API key from the API Keys section. Free trial credit is usually included for new accounts. Store the key in a .env file (never commit it).

What is the difference between AsyncAnthropic and Anthropic?

Anthropic is the synchronous client (blocking calls). AsyncAnthropic uses asyncio for concurrent requests, required if you call multiple Claude requests in parallel from FastAPI or AIOHTTP. Same API surface, just add await.

Which Claude model should I use in 2026?

claude-opus-4-7 for the best quality on complex reasoning. claude-sonnet-4-6 for fast everyday tasks. claude-haiku-4-5 for high-volume cheap tasks. Pricing scales accordingly. Newer Opus 4.8 may be available; check console.anthropic.com/models for current list.

Can the anthropic SDK use AWS Bedrock or Google Vertex?

Yes. Install pip install ‘anthropic[bedrock]’ and use AnthropicBedrock client (uses AWS IAM credentials). Or pip install ‘anthropic[vertex]’ for AnthropicVertex (uses GCP creds). Same message API.

Does anthropic SDK support function calling and tool use?

Yes. Pass tools parameter to messages.create. Claude returns tool_use blocks; you execute the tool and send back tool_result. Powers everything from RAG to multi-step agents. See the SDK README for the complete loop.

Leave a Comment