3

I tried:

  • pip install python-telegram-bot
  • pip3 install python-telegram-bot
  • pip install telegram
  • pip3 install telegram

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

user19499885
  • 71
  • 1
  • 1
  • 5
  • Welcome to Stack Overflow. Are you getting the error from running your code or installing? Are you using python2 or python3? If you're getting the error from running, please clarify how you installed the telegram module and how you're running your code. Which python installation? – ewokx Jul 07 '22 at 05:37

6 Answers6

4

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.

user19499885
  • 71
  • 1
  • 1
  • 5
1

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
Eggcellentos
  • 1,570
  • 1
  • 18
  • 25
Enzo
  • 21
  • 5
1
pip3/pip uninstall python-telegram-bot
pip3/pip uninstall telegram
pip3/pil install python-telegram-bot==13.14

This method solved my problem

Moein
  • 13
  • 3
0

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

ificiana
  • 98
  • 7
  • Thank you so much for your comment, I faced similar namespace problem due to my own file naming mistake as detailed in the solution. – user19499885 Jul 07 '22 at 08:27
  • Ah yes, that too can cause such a problem, local modules get higher priority than global modules. Glad I could help somehow :) – ificiana Jul 07 '22 at 15:51
0

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)

arg
  • 51
  • 3
0

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.

this worked for me

Pady
  • 9
  • 2