How to Install websockets in Python

v16.0 Async & Networking Python >=3.10

An implementation of the WebSocket Protocol (RFC 6455 & 7692)

Install pip install websockets

What is websockets?

An implementation of the WebSocket Protocol (RFC 6455 & 7692)

websockets is a library for building WebSocket servers and clients in Python with a focus on correctness, simplicity, robustness, and performance.

Built on top of ``, Python's standard asynchronous I/O framework, the default implementation provides an elegant coroutine-based API.

An implementation on top of `` and a Sans-I/O implementation are also available.

Quick Start

Minimal example to get started with websockets:

import websockets

print(websockets.__version__)

Installation

pip (standard)

pip install websockets

Virtual environment (recommended)

python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate
pip install websockets

pip3

pip3 install websockets

conda

conda install -c conda-forge websockets

Poetry

poetry add websockets

Verify the Installation

After installing, confirm the package is available:

python -c "import websockets; print(websockets.__version__)"

If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.

Installation Errors

Common errors when installing websockets with pip.

ModuleNotFoundError: No module named 'websockets'

Cause: The package is not installed in the current Python environment.

Fix: Run pip install websockets. If using a virtual environment, ensure it is activated first.

ModuleNotFoundError: No module named 'websockets' (installed but still failing)

Cause: pip installed the package into a different Python than the one running your script.

Fix: Use python -m pip install websockets to install into the interpreter you are running.

ImportError: cannot import name 'X' from 'websockets'

Cause: The function or class does not exist in the installed version.

Fix: Check the version with pip show websockets and upgrade with pip install --upgrade websockets.

pip: command not found

Cause: pip is not in PATH or Python was not added to PATH during installation.

Fix: Try python -m pip install websockets. On macOS/Linux try pip3.

PermissionError: [Errno 13] Permission denied

Cause: No write access to the system Python package directory.

Fix: Use a virtual environment, or add --user: pip install --user websockets

SSL: CERTIFICATE_VERIFY_FAILED

Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.

Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org websockets

RuntimeError: This event loop is already running

Cause: Calling <code>asyncio.run()</code> inside Jupyter or another already-running event loop.

Fix: In Jupyter, use await directly. Or install nest_asyncio and call nest_asyncio.apply().

Recent Releases

VersionReleased
16.0 latest 2026-01-10
15.0.1 2025-03-05
15.0 2025-02-16
14.2 2025-01-19
14.1 2024-11-13

Full release history on PyPI →

Manage websockets

Upgrade to latest version

pip install --upgrade websockets

Install a specific version

pip install websockets==16.0

Uninstall

pip uninstall websockets

Check what is installed

pip show websockets

Last updated: 2026-04-11 • Data from PyPI