2026, Jan 10 13:00
HTTP/2 with httpx on WSL: how to fix the missing h2 dependency and pip's externally managed environment
Enable HTTP/2 in httpx on WSL without errors. Learn to resolve the missing h2 package and pip externally managed environment using python -m pip or a venv.
Getting HTTP/2 working with httpx in a WSL environment can be unexpectedly tricky. You enable http2=True, but the client complains about a missing dependency; then pip refuses to cooperate due to externally managed packages. The good news is that this is a simple dependency and environment alignment issue, and it’s straightforward to resolve without changing your code logic.
What the error looks like
The trigger is a typical HTTP client setup where HTTP/2 is turned on. For example:
import httpx
with httpx.Client(http2=True) as net_client:
reply = net_client.get("https://example.com")
When the required dependency is missing, you’ll see a message like this:
Error: Using http2=True, but the 'h2' package is not installed. Make sure to install httpx using `pip install httpx[http2]`.
Why it happens
httpx does not bundle HTTP/2 support by default. The extra httpx[http2] adds a single dependency: the h2 package. In WSL, attempting to install that extra with pip may hit the externally-managed-environment restriction, which blocks direct modifications to the system Python environment. Using the wrong pip entry point can also point installations at a different interpreter than the one you actually run. In contrast, python -m pip invokes pip for the exact Python interpreter you’re using, which keeps the environment consistent.
Two reliable ways to fix it
The simplest path is to install the dependency directly for the current user. This bypasses system-level restrictions and ensures that httpx and h2 land in the same environment:
python3 -m pip install --user httpx h2
If you prefer full isolation—and to avoid system-level limitations entirely—create and activate a virtual environment, then install the extra as intended:
python3 -m venv venv
source venv/bin/activate
pip install httpx[http2]
After that, the same client code with http2=True should work as expected in WSL.
Why this detail matters
HTTP/2 testing often sits at the edge of networking and tooling, and environment mismatches can derail your workflow. Knowing that httpx[http2] merely adds the h2 dependency clarifies where to look when things fail. Using python -m pip reduces ambiguity about which interpreter and site-packages directory are being modified, which is especially important inside WSL where multiple Python installations and package managers may coexist.
Wrap-up and practical advice
If httpx complains about missing HTTP/2 support, install h2 alongside httpx with python3 -m pip install --user httpx h2, or switch to a virtual environment and run pip install httpx[http2]. Keep using python -m pip to ensure you’re talking to the correct interpreter. With that in place, your HTTP/2 requests from WSL will proceed without surprise blockers.