user19499885
user19499885

Reputation: 81

ModuleNotFoundError: No module named 'telegram.ext'; 'telegram' is not a package

I tried:

But the error keeps showing up telling me there is no such package of 'telegram.ext' offered by python-telegram-bot. However, my text editor with python plugin is able to find the package telegram.ext in my environment. I also tried using command prompt dirtectly on that virtual environment I created, still doesn't work. Seems that this same issue is faced by other posts on internet without any resolve.

my text editor plugin can find the package

Upvotes: 3

Views: 20541

Answers (6)

Pady
Pady

Reputation: 11

your file is called telegarm.py well, at least mine was.

rename your python file to something like telegram-bot.py and it should work fine.

Upvotes: 0

Moein
Moein

Reputation: 13

pip3/pip uninstall python-telegram-bot
pip3/pip uninstall telegram
pip3/pil install python-telegram-bot==13.14

This method solved my problem

Upvotes: 1

arg
arg

Reputation: 51

If Python API for the tdlib library is being used then, as per Tutorial https://python-telegram.readthedocs.io/en/latest/tutorial.html Install the library:

python3 -m pip install python-telegram

(or simply python instead of python3 for some environments)

Upvotes: 0

Enzo
Enzo

Reputation: 41

Do 1-2 via terminal and 4 on your IDE:

  1. Install pip install telegram
  2. Install pip install python-telegram-bot
  3. If you are using a virtual environment, make sure it is activated
  4. Lastly, import from telegram.ext import

Upvotes: 1

user19499885
user19499885

Reputation: 81

I just realized the error was because there was another file named 'telegram.py' in the same directory causing the package import problem. Sorry for this silly mistake. Thank you and I will close the case.

Upvotes: 5

ificiana
ificiana

Reputation: 98

It seems both packages python-telegram-bot and telegram uses the same namespace "telegram". This can cause conflicts, so you should remove one of them.

This uninstalls the telegram package

pip uninstall telegram

Note: use pip3 if on Linux or Mac

Upvotes: 0

Related Questions