If you see the error RuntimeError: aiohttp requires Python 3.4.2+ when trying to use the aiohttp package in your Python application, it means your Python version is too old.
The aiohttp package relies on new features and improvements introduced in Python 3.4.2 and later versions. So to fix this error, you need to upgrade your Python installation to 3.4.2 or newer.
Upgrading Python
The easiest way to upgrade is by installing a newer Python version directly from the Python website:
- Go to python.org and download the latest 3.X version (3.7 or 3.8 at the time of writing).
- Run the installer and make sure to check the box to add Python to your system PATH.
- Open a new command prompt window and check that the new Python version is running by typing
python --version .
Alternatively, if you're using a distribution like Anaconda, you can create a new Conda environment with Python 3.5 or later:
conda create -n aiohttp_env python=3.8
Then activate the environment before running your aiohttp application.
Pinning aiohttp Version
In some cases, even after upgrading Python, you may need to pin the aiohttp version in your
aiohttp>=3.0.0
This will install aiohttp 3.x or later which requires Python 3.5+.
Upgrading Python and pinning an up-to-date aiohttp version should resolve the runtime error. The key is to make sure you are running Python 3.4.2 or newer to take full advantage of the performance improvements and features that aiohttp relies on.