How to fix ImportError: No module named 'telebot'
Asked Answered
A

2

5

I'm configuring a bot to send alerts from Zabbix, so I installed Python and the modules:

sudo apt install python python-pip python-setuptools

After that, I installed the bot API to use on Zabbix:

python -m pip install --user pyTelegramBotAPI

Created the script in /usr/lib/zabbix/alertscripts/ :

#!/usr/bin/env python
     
import telebot,sys
     
BOT_TOKEN='123TOKENAQUI321'
DESTINATION=sys.argv[1]
SUBJECT=sys.argv[2]
MESSAGE=sys.argv[3]
     
MESSAGE = MESSAGE.replace('/n','\n')
tb = telebot.TeleBot(BOT_TOKEN)
tb.send_message(DESTINATION,SUBJECT + '\n' + MESSAGE)

Changed permissions:

sudo chmod +x telegram

sudo chown -R zabbix telegram

And when testing the script on terminal or Zabbix the following error appears:

Traceback (most recent call last): File "/usr/lib/zabbix/alertscripts/telegram", line 2, in import telebot,sys ImportError: No module named 'telebot'

I tried to solve by installing the module:

python -m pip install --user telebot

Installing the module did not solve it, so I tried to use python3, and the script on the terminal worked, but in Zabbix still showing the same error. I ended up going back to python.

The telebot module does not appear with pip list, only inside the python terminal using the command help ("modules").

What may be causing the problem and how to resolve it?

Angele answered 26/9, 2019 at 16:29 Comment(2)
are you using python3? Try using pip3 install instead of pip install.Explain
I already tried with python3 and pip3, then it worked sending messages through the terminal, but in Zabbix still giving the same error.Angele
A
8

I managed to solve it using python3, but this time I removed the other versions of python completely before installing again, the steps were as follows:

sudo python -m pip uninstall pyTelegramBotAPI
sudo apt remove python python-pip python-setuptools
sudo apt install python3 python3-pip python3-setuptools python3-six
sudo python3 -m pip install pyTelegramBotAPI six
sudo pip install six
Angele answered 27/9, 2019 at 12:43 Comment(0)
E
1

For like these errors, reinstall the library or use (--upgrade) when you install it!

like this:

pip uninstall telebot
pip install pyTelegramBotAPI
pip install pytelegrambotapi --upgrade
Extemporaneous answered 22/12, 2021 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.