pythonwindows-subsystem-for-linuxhttpx

How to install httpx[http2] in WSL2


I'm making a python program to test a web-server I am making. I use httpx and wanted to use http2 as well, to be able to send http version 2 requests. The only way I find to install it is pip install httpx[http2], but pip is not working on WSL (error: externally-managed-environment). I got around this with https by doing python3-pip install httpx but python3-pip install httpx[http2] does not seem to work or any other variants I have tried.

To clarify both my web server and python program is running in WSL.

The error that made me look into http2 was:

Error: Using http2=True, but the 'h2' package is not installed. Make sure to install httpx using `pip install httpx[http2]`.


Solution

  • httpx[http2] just adds the h2 package try adding it manually by :

    python3 -m pip install --user httpx h2
    

    and i recommend to use virtual environment as it avoids any system level limitations:

    python3 -m venv venv
    
    source venv/bin/activate
    
    pip install httpx[http2]
    

    it should work now