I am trying to make a simple telegram bot that just sends some text back. I am working with Pycharm. My program:
import time
import telepot
def add(chat_id, msg):
bot.sendMessage(chat_id, 'add')
def age(chat_id, msg):
bot.sendMessage(chat_id, 'age')
def remove(chat_id, msg):
bot.sendMessage(chat_id, 'remove')
def birthday(chat_id, msg):
bot.sendMessage(chat_id, 'birthday')
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
print('Got command: %s' % command)
print(chat_id)
if '/birthday' in command:
birthday(chat_id, msg)
elif '/add' in command:
add(chat_id, msg)
elif '/remove' in command:
remove(chat_id, msg)
elif '/age' in command:
age(chat_id, msg)
bot = telepot.Bot('<My token>')
bot.notifyOnMessage(handle)
print('I am listening ...')
while 1:
time.sleep(10)
If I run my program in a terminal, it works fine, but if I try to run it with Pycharm, this is what I get back.
/usr/bin/python3.4 /home/omer/PycharmProjects/RelAgeBot/RelAgeBot.py
Traceback (most recent call last):
File "/home/omer/PycharmProjects/RelAgeBot/RelAgeBot.py", line 17, in <module>
import telepot
File "/usr/local/lib/python3.4/dist-packages/telepot/__init__.py", line 17, in <module>
requests.packages.urllib3.disable_warnings()
AttributeError: 'module' object has no attribute 'packages'
Process finished with exit code 1
I have installed the 'telepot' package with pip on a terminal and again with Pycharm, but it does not seem to work.
To answer my own question, after @dursk commented that the problem may be with the module 'requests', I tried to update it again. I do not know exactly why, but Pycharm did not update this module. After I tried updating it a few times, it was updated. Now it works.
So in Pycharm go to the Settings > Project > Project Interpreter. In this list search for the package you are looking for and dubble click it. Click the option to download a specific version and choose the latest. And then just click install and you are done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With