4

I am trying to run the below program using asyncio:

import asyncio

async def main():
    print('Hello')
    await asyncio.sleep(1)
    print('World')

asyncio.run(main())

However, I am getting the following error:

AttributeError: module 'asyncio' has no attribute 'run'

python --version gives: Python 2.7.8

python3 --version gives: Python 3.7.1

I am running the script as python3 script.py

Any ideas on how can I run this program without any error?

2 Answers 2

19

My bet: your script.py file actually has name asyncio.py (or you have such file somewhere in PYTHONPATH). Rename it to something different and everything will work.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks a lot. I had another file called asyncio.py lying in my machine.
@Mihika you're welcome. I think there's no Python developer on a planet who didn't face or won't face this situation :)
guess what was the name of my python file .... shame on me ... thanks Mihika
I'm new to python and I was naming the file asyncio.py 😂😂
I did named asynciol.py, you saved my day!!
3

I am late to the party, but I faced the same issue while trying to run a fastapi program onto Azure App Services.

I could not find any asyncio.py onto my system, as suggested by @Mikhail Gerasimov, but the fix described here did the trick:

pip uninstall uvicorn
pip install uvicorn==0.16.0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.