Python에서 telegram을 사용할 때 No module named 'Bot'이 문구가 뜨는 경우
예제 소스
import telegram
import asyncio
async def telegram_alert(failtext):
token = "TOKEN"
bot = telegram.Bot(token)
await bot.sendMessage(chat_id='chat_id', text=failtext)
asyncio.run(telegram_alert("telegram_message"))
에러 내용
Exception has occurred: AttributeError
partially initialized module 'telegram' has no attribute 'Bot' (most likely due to a circular import)
File "C:\telegram.py", line 6, in telegram_alert
bot = telegram.Bot(token)
File "C:\telegram.py", line 9, in <module>
asyncio.run(telegram_alert("telegram_message"))
File "C:\telegram.py", line 1, in <module>
import telegram
AttributeError: partially initialized module 'telegram' has no attribute 'Bot' (most likely due to a circular import)
보통 해당 모듈이 없어 설치가 필요하거나
삭제 후 재설치, 업데이트를 하면 메시지가 사라진다.
설치 : pip install python-telegram-bot
재설치 : pip uninstall python-telegram-bot // pip install python-telegram-bot
업그레이드 : pip install python-telegram-bot --upgrade
하지만 설치나 재설치를 진행해도 계속해서 아래 에러가 뜬다면
python 파일명을 의심해 봐야한다.
파일명이 telegram.py로 되어있는 경우 모듈 설치를 진행해도 계속 에러가 뜬다.
파일명을 바꾸면 더 이상 에러가 발생하지 않는다.