简体   繁体   English

如何修复 ImportError:没有名为“telebot”的模块

[英]How to fix ImportError: No module named 'telebot'

I'm configuring a bot to send alerts from Zabbix, so I installed Python and the modules:我正在配置一个机器人从 Zabbix 发送警报,所以我安装了 Python 和模块:

sudo apt install python python-pip python-setuptools

After that, I installed the bot API to use on Zabbix:之后,我安装了机器人 API 以在 Zabbix 上使用:

python -m pip install --user pyTelegramBotAPI

Created the script in /usr/lib/zabbix/alertscripts/ :/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:在终端或 Zabbix 上测试脚本时,会出现以下错误:

Traceback (most recent call last): File "/usr/lib/zabbix/alertscripts/telegram", line 2, in import telebot,sys ImportError: No module named 'telebot'回溯(最后一次调用):文件“/usr/lib/zabbix/alertscripts/telegram”,第 2 行,在 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.安装模块并没有解决,所以我尝试使用python3,终端上的脚本可以工作,但是在zabbix中仍然显示同样的错误。 I ended up going back to python.我最终回到了 python。

The telebot module does not appear with pip list , only inside the python terminal using the command help ("modules") .远程机器人模块不会出现在pip list ,仅在 python 终端内使用命令help ("modules")出现。

Does anyone know that may be causing the problem?有谁知道这可能会导致问题?

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:我设法使用python3解决了它,但是这次我在再次安装之前完全删除了python的其他版本,步骤如下:

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

Thanks a lot: This one is helped, "python -m pip install --user pyTelegramBotAPI", i understood than i need to use "python 3 -m pip install --user pyTelegramBotAPI" instead.非常感谢:这个有帮助,“python -m pip install --user pyTelegramBotAPI”,我明白我需要使用“python 3 -m pip install --user pyTelegramBotAPI”代替。

For like these errors, reinstall the library or use (--upgrade) when you install it!对于这些错误,请重新安装库或在安装时使用 (--upgrade) !

like this:像这样:

pip uninstall telebot
pip install pyTelegramBotAPI
pip install pytelegrambotapi --upgrade

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM