To install LangChain in Python, run python -m pip install -U langchain from a supported Python environment. The current LangChain installation documentation requires Python 3.10 or newer. Once your environment is ready, our LangChain memory tutorial explains how to retain conversation state. Install the provider package separately if you intend to connect to a model such as OpenAI or Anthropic. To connect external MCP tools, follow the LangChain MCP adapter setup guide.
For a new project, create a virtual environment before installing anything. For commercial deployments, review the LangChain MIT license requirements and the terms of your dependencies. This prevents packages from unrelated projects from interfering with each other and helps you verify that pip installs into the interpreter that actually runs your code.
This guide follows the current LangChain installation and quickstart documentation reviewed November 29, 2026. The commands are documented setup examples; a live package installation and model request were not completed in our test environment.
Quick installation with pip
If you already have an active virtual environment and a compatible version of Python, these are the two commands to start with:
python --version
python -m pip install -U langchain
The first command identifies the interpreter. The second installs the main package and its declared dependencies, upgrading the package if necessary. Using Python to invoke pip is more reliable than a standalone pip command when several Python installations exist.
For existing applications, do not automatically upgrade a production environment. Review its dependency constraints and create a separate test environment before changing installed versions.
Set up a Python virtual environment
macOS and Linux
Open a terminal and create an empty project folder. Use a supported Python interpreter; Python 3.11 or 3.12 is a practical starting point for many projects, subject to the requirements of your chosen integrations.
mkdir langchain-project
cd langchain-project
python3 --version
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -U langchain
Windows PowerShell
Use the Python launcher if it is installed. Select a supported Python version available on your computer. This example uses Python 3.12; replace it with your installed compatible version if necessary.
mkdir langchain-project
cd langchain-project
py -3.12 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -U langchain
If PowerShell prevents activation scripts from running, you do not need to weaken your system execution policy. You can run the virtual environment’s interpreter directly:
.\.venv\Scripts\python.exe -m pip install -U langchain
.\.venv\Scripts\python.exe -m pip show langchain
On macOS and Linux, the equivalent direct interpreter is .venv/bin/python. Activation is a shell convenience; the environment itself already exists once venv has created it. When you finish working in an activated environment, run deactivate.
Install the right LangChain packages
LangChain is an ecosystem of packages rather than one download containing every model and database integration. Start with the main library, then install only the additional integrations your application needs.
| Package | When to install it |
|---|---|
| langchain | High-level agent and application interfaces |
| langchain-core | Core abstractions when you only need those interfaces; usually installed as a dependency |
| langchain-openai | OpenAI provider integration |
| langchain-anthropic | Anthropic provider integration |
| langchain-google-genai | Google generative AI integration |
| langgraph | Direct state-graph orchestration |
| langchain-classic | Compatibility with selected older chains and APIs, when required |
For an OpenAI-based project, install the main library and the OpenAI provider integration together. For Anthropic, use its provider package instead. Let the resolver select compatible dependencies.
python -m pip install -U langchain langchain-openai
Alternatively, for Anthropic:
python -m pip install -U langchain langchain-anthropic
Avoid installing a large collection of provider packages just because a tutorial lists them. Additional dependencies increase the number of versions to maintain and can introduce avoidable conflicts. If you need lower-level graph orchestration, our guide to what LangGraph is explains the distinction from LangChain.
Verify your installation without an API key
Installation verification should not require an API key or a paid model request. Check the environment, the package version, its dependency consistency and the imports that your script will use.
python -m pip --version
python -m pip show langchain
python -m pip check
python -c "import sys; print(sys.executable)"
python -c "from importlib.metadata import version; print(version('langchain'))"
The pip location and Python executable should point to the intended virtual environment. The package version command should print an installed version number. A successful pip check reports that no broken dependency requirements were found.
For a current LangChain agent project, check whether the high-level agent API is importable:
python -c "from langchain.agents import create_agent; print('Agent import OK')"
For an OpenAI project, check the integration independently:
python -c "from langchain_openai import ChatOpenAI; print('Provider import OK')"
These import checks demonstrate that the selected interfaces can be loaded. They do not prove that a model endpoint is accessible or that your API account is authorized. A model call is a separate test.
Connect a model provider safely
A provider integration needs access to a model. For a hosted provider, create credentials through an approved account and use an environment variable or your organization’s secret manager. Never paste a real key into a shared source file, commit it to Git, or log it.
For a local development session, set the key using your operating system’s approved secret handling method. The following Python check reports whether a key exists without displaying its value.
import os
if not os.getenv('OPENAI_API_KEY'):
raise RuntimeError('Set OPENAI_API_KEY before running the app')
print('API key is configured')
A minimal agent setup can then create an agent with a model that your provider account supports. Replace the placeholder with an actual available model identifier; do not run this as written without choosing one.
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
model = ChatOpenAI(model='YOUR_SUPPORTED_MODEL_ID')
agent = create_agent(model=model, tools=[])
result = agent.invoke({
'messages': [{'role': 'user', 'content': 'Say hello.'}]
})
print(result['messages'][-1].content)
This illustrative model call requires an available account, valid credentials, network access and a supported model. It may incur provider charges. The installation itself does not require a paid model call. For a complete introduction to tool-enabled agents using a different SDK, see our agentic AI tutorial.
Fix common installation and import errors
No module named langchain or langchain_openai
First check whether the Python environment running your script is the same one in which you installed the package. The package name and import name can also differ: install langchain-openai with pip, then import langchain_openai in Python.
python -c "import sys; print(sys.executable)"
python -m pip show langchain langchain-openai
In an IDE or Jupyter notebook, select the interpreter or kernel belonging to your virtual environment. A successful install in a terminal does not automatically change your notebook kernel.
No matching distribution found
Check Python’s version and pip’s configured package index. Current LangChain releases require a supported Python version, so an old interpreter can prevent installation. A private or restricted package index can also lack a compatible release. Use your organization’s approved package repository and avoid downloading random wheel files from unknown sources.
Dependency conflicts or ResolutionImpossible
The resolver may detect incompatible requirements across installed or requested packages. Inspect the exact error rather than forcing installation with dependency checks disabled. In a fresh environment, install the main framework and only the integrations required for the project. For an existing project, compare the version constraints against your requirements and test a compatible set.
Externally managed environment or permission errors
Some operating systems protect the system Python installation against direct pip changes. Create a virtual environment instead of using administrator privileges or disabling the protection. This also makes the project easier to reproduce on another machine.
SSL certificate verification errors
A certificate failure can indicate a network or trust configuration problem. Check the system clock, certificate configuration, approved package index and organizational proxy settings. Do not disable TLS verification to bypass an installation problem. Ask your IT administrator for the approved certificate configuration if needed.
Old LangChain imports no longer work
An older tutorial may import a class from a location that has changed. Installing the latest LangChain release does not guarantee that code written for an earlier API will run unchanged. Modern agent interfaces and legacy chain APIs are organized differently. Check the current documentation for your version; use a compatible legacy environment only when the project genuinely requires it.
If your underlying issue is architecture rather than installation, our LangChain alternatives guide and Haystack vs. LangChain comparison explain other framework options.
Upgrade, pin, or remove LangChain
Once an application works, record the tested dependency versions. Avoid relying on whichever package versions happen to be newest when deploying the application later.
python -m pip freeze > requirements.txt
python -m pip check
The freeze command captures installed versions from the environment, including transitive dependencies. Review the resulting file before committing it. It can contain local or environment-specific references, so treat it as an environment snapshot rather than a universally portable lockfile.
To reproduce the environment, create a new virtual environment using a compatible Python version and install the reviewed requirements:
python -m pip install -r requirements.txt
python -m pip check
To upgrade, use a separate test environment, update the required packages together and run application tests. To remove LangChain from a disposable environment, run:
python -m pip uninstall langchain
Uninstalling the main package does not automatically remove every transitive dependency or separately installed provider integration. Recreating a disposable virtual environment is often cleaner than manually removing a large dependency tree.
Frequently asked questions
Can I install LangChain with pip on Windows?
Yes. Use a compatible Python installation, create a virtual environment, then run python -m pip install -U langchain from that environment.
Do I need an OpenAI API key to install LangChain?
No. You can install and import the package without credentials. A hosted model request generally requires an authorized account and a valid API key.
Does installing LangChain install all integrations?
No. Install the provider and other integration packages needed by your project. The main package includes its declared core dependencies, not every optional integration.
Why does pip say LangChain is installed but Python cannot import it?
The script or notebook may use a different Python interpreter. Compare sys.executable and python -m pip –version, then install into the intended environment.
Is pip install -U langchain the right command for every project?
It is appropriate for a new isolated environment. For an existing application, preserve its tested dependencies and upgrade only after checking compatibility.

