每当我 运行 需要 aiohttp 库的代码时出错

Error whenever I run code that requires aiohttp library

每当我 运行 需要 aiohttp 的代码时,我都会收到以下错误:

Traceback (most recent call last):
  File "C:\Users\HP\.atom\async8.py", line 1, in <module>
    from aiohttp import web
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\__init__.py", line 6, in <module>
    from .client import *  # noqa
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\client.py", line 15, in <module>
    from . import connector as connector_mod
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\connector.py", line 13, in <module>
    from . import hdrs, helpers
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\helpers.py", line 30
    ensure_future = asyncio.async
                            ^
SyntaxError: invalid syntax

我尝试 运行 来自 https://docs.aiohttp.org/en/stable/ 的代码示例包括:

import aiohttp
import asyncio

async def main():

    async with aiohttp.ClientSession() as session:
        async with session.get('http://python.org') as response:

            print("Status:", response.status)
            print("Content-type:", response.headers['content-type'])

            html = await response.text()
            print("Body:", html[:15], "...")

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

    from aiohttp import web

async def handle(request):
    name = request.match_info.get('name', "Anonymous")
    text = "Hello, " + name
    return web.Response(text=text)
    

app = web.Application()
app.add_routes([web.get('/', handle),
                web.get('/{name}', handle)])

if __name__ == '__main__':
    web.run_app(app)

我已经尝试了其他几个示例,但它们都产生了相同的错误。是什么原因造成的?我正在使用 python 3.8.6 和最新版本的 aiohttp

更新: 错误似乎是由导入 aiohttp 引起的。我只是通过在 cmd.

上输入 'import aiohttp' 得到了错误

看来 pip install aiohttp 安装的版本与我当前的 python 版本不兼容。 pip install aiohttp==3.5.4 帮我解决了这个问题。感谢@edoput 指出这一点。