AttributeError: module 'asyncio' has no attribute 'run'
AttributeError: module 'asyncio' has no attribute 'run'
我正在尝试 运行 使用 asyncio 的以下程序:
import asyncio
async def main():
print('Hello')
await asyncio.sleep(1)
print('World')
asyncio.run(main())
但是,我收到以下错误:
AttributeError: 模块 'asyncio' 没有属性 'run'
python --version 给出:Python 2.7.8
python3 --版本给出:Python 3.7.1
我运行将脚本设置为python3 script.py
关于如何 运行 这个程序没有任何错误有什么想法吗?
我敢打赌:您的 script.py
文件实际上具有名称 asyncio.py
(或者您在 PYTHONPATH
中某处有这样的文件)。将其重命名为不同的名称,一切都会正常工作。
我正在尝试 运行 使用 asyncio 的以下程序:
import asyncio
async def main():
print('Hello')
await asyncio.sleep(1)
print('World')
asyncio.run(main())
但是,我收到以下错误:
AttributeError: 模块 'asyncio' 没有属性 'run'
python --version 给出:Python 2.7.8
python3 --版本给出:Python 3.7.1
我运行将脚本设置为python3 script.py
关于如何 运行 这个程序没有任何错误有什么想法吗?
我敢打赌:您的 script.py
文件实际上具有名称 asyncio.py
(或者您在 PYTHONPATH
中某处有这样的文件)。将其重命名为不同的名称,一切都会正常工作。