Although I install python-telegram-bot, error of no module named 'telegram'

Question:

I installed telegram packages. But when I try to run the simple example, echobot.py, I got an error:

Traceback (most recent call last):
    File "echobot.py", line 8, in <module>
import telegram ImportError: No module named 'telegram'

Can anyone help me?

I install using git:

$ git clone https://github.com/python-telegram-bot/python-telegram-bot

after this:

$ python -i
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import telegram

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ImportError: No module named 'telegram'
Asked By: Mahyar

||

Answers:

You are not installing it. You are just downloading it.
Run these:

cd python-telegram-bot
python setup.py install

(stated in readme of the GitHub page)

Alternatively, you can use pip. It’s easier to use.

pip install python-telegram-bot
Answered By: cagri

Thre problem is in line with smth like

sys.path.append(os.path.join(os.path.abspath('.'), 'lib'))

in bot_gae.py.

You have to point at REAL place, where you’ve installed python-telegram-bot.

In my case it’s ./lib in project directory.

Install

pip install django-telegrambot

Configure your installation

settings.py

INSTALLED_APPS = (

‘django_telegrambot’,
)

Answered By: Adnan Rizwee

For my case, I solved it this way.enter image description here

pip install telegram
Answered By: Md.Rakibuz Sultan

I noticed when I import telegram.ext, it does not find .ext. The issue was caused by telegram and python-telegram modules being installed. Delete these and install only python-telegram-bot. It should work.

Answered By: Leon Liju

If you have named your python file as telegram.py then it will throw this error because the program is calling ext function from the file itself.
Try renaming your python file to something else it will work.

Answered By: Harshit Agrawal

In my case, I had two python versions installed.
A quick solution is to idetify which python your code is using. Then go to bin directory where the python is installed. Find the pip binary name inside that using command

ls -lrt | grep pip

In my cases the name was pip3.6. So use then use that pip name and execute from same directory

pip3.6 install python-telegram-bot

Long term fix is to add your pip3.6 shortcut in /usr/bin or /usr/loca/bin and install packages using pip3.6 command

Answered By: Ganesh S

Try to uninstall it by pip uninstall python-telegram-bot

And after that install it again pip install python-telegram-bot

Answered By: Weird Dude