module 'asyncio' has no attribute 'run'
时间: 2023-09-04 17:16:50 浏览: 87
报错"module 'asyncio' has no attribute 'run'"是由于使用的Python版本不支持asyncio的run方法引起的。这个错误通常在Python版本低于3.7时出现,因为asyncio.run方法是在Python 3.7版本中引入的。所以如果你的Python版本不够新,就会出现这个错误。解决这个问题的方法有两种:
1. 升级Python版本:推荐将Python升级到3.7或更高的版本,这样就可以使用asyncio.run方法了。
2. 使用其他方法代替asyncio.run:如果升级Python版本不可行,你可以尝试使用其他方法来代替asyncio.run。例如,你可以使用asyncio.get_event_loop().run_until_complete()方法来运行异步代码。你可以将你的代码修改为以下形式:
```
loop = asyncio.get_event_loop()
loop.run_until_complete(self.serve(sockets=sockets))
```
通过这种方式,你可以在较旧的Python版本中运行你的代码,而不会出现"module 'asyncio' has no attribute 'run'"的错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [python module 'asyncio' has no attribute 'run'](https://blog.csdn.net/brightgreat/article/details/125270843)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [AttributeError: module ‘asyncio‘ has no attribute ‘run](https://blog.csdn.net/qq_34435096/article/details/126882021)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]