python module 'asyncio' has no attribute 'run'

当在Python中遇到'asyncio'模块没有'run'方法的错误时,可能是因为Python版本低于3.7。确保使用3.7或更高版本,或者检查项目中是否存在名为'asyncio.py'的文件导致的命名冲突。升级Python版本或重命名冲突文件可解决此问题。
摘要由CSDN通过智能技术生成

python 使用uvicorn运行时报错module 'asyncio' has no attribute 'run'

很大可能是python的版本太低了
因为python3.7 及以后才支持run方法
或者是看一下你的项目文件里是不是命名了一个asyncio.py的文件,和运行的文件冲突了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
报错"module 'asyncio' has no attribute 'run'"是由于使用的Python版本不支持asynciorun方法引起的。这个错误通常在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: moduleasyncio‘ has no attributerun](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 ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值