J-Rios / TLG_JoinCaptchaBot

Telegram Bot to verify if users joining a group are human. The Bot sends an image captcha for each new user and kicks any of them who can't solve the captcha in a specified time.
GNU General Public License v3.0
520 stars 217 forks source link

[Question] Own Bot instance deployment failure (ImportError: cannot import name 'MessageEntity' from 'telegram') #11

Closed marcopaganini closed 4 years ago

marcopaganini commented 4 years ago

Hello,

I'm trying to create a Docker for TLG_JoinCaptchaBot. I've followed all instructions on the README.md (with the change of changing libjpeg8 to libjpeg62-turbo, as libjpeg8 is not available on Debian). I've installed the requirements with pip3 (Debian's python3 version of pip). When I try to run the bot, I get:

Traceback (most recent call last):
  File "join_captcha_bot.py", line 34, in <module>
    from telegram import MessageEntity, ParseMode, InputMediaPhoto,  InlineKeyboardButton, \
ImportError: cannot import name 'MessageEntity' from 'telegram' (/usr/local/lib/python3.7/dist-packages/telegram/__init__.py)

Running python3 by hand and attempting to import the library above gives me the same result, as expected.

The curious thing is that I don't see this module under the "telegram" library. Any ideas?

J-Rios commented 4 years ago

Hi,

Here is some ideas:

Are you sure that the installed python-telegram-bot library is last stable version (the one in requirements file), 11.1.0?

pip3 freeze | grep -e "python-telegram-bot"
python3 -c "import telegram; print(telegram.__version__)"

Are you sure that you have installed the requeriments into python 3.7? May your pip3 point to another remaining python3 version (i.e. 3.4)?

pip3 -V

Is "MessageEntity" imported in Telegram lib init file?

cat -n /usr/local/lib/python3.7/dist-packages/telegram/__init__.py | grep -e "MessageEntity"

You have tried a basic import test of python-telegram-bot library without joincaptchabot, have you try importing that submodule and importing full telegram module?

python3 -c "from telegram import MessageEntity"
python3 -c "import telegram; print(telegram.MessageEntity)"
marcopaganini commented 4 years ago

So, I ended up making it work by removing the "telegram" library completely. Everything seems to be working fine now. Why do we need both telegram and python_telegram_bot libraries? Note that in my case, /usr/local/lib/python3.7/dist-packages/telegram/__init__.py was just a placeholder with a "not implemented" print in the init class.

BTW, if you're interested, I can submit a PR with the Dockerfile and the instructions to create a container, plus some other project contributions.

J-Rios commented 4 years ago

Nice to hear that it is working.

Not sure why there is two telegram libraries in requirements file, maybe I have install "telegram" for some reason time ago, and won't notice that it is not part of python-telegram-bot library when generate requirements file. I have test installation and bot usage without it and it is working, so I'm going to remove "telegram==0.0.1" line from requirements file.

Any contibution will be appreciated, maybe you can add Docker container usage in a new README file section or create a new "docs" directory with that info and point to the file in the readme file. And maybe take a look if there is a good way to set Bot token without manual entering the container...