AttributeError:'module'对象没有属性'packages'Pycharm 5.0.1

时间:2015-12-06 00:47:09

标签: python python-3.x pycharm

我正在尝试制作一个只发送一些文本的简单电报机器人。我正在使用Pycharm。 我的节目:

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)

如果我在终端中运行我的程序,它运行正常,但如果我尝试使用Pycharm运行它,这就是我得到的。

/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

我已经在终端上安装了带有pip的'telepot'软件包,再次使用Pycharm,但它似乎没有用。

1 个答案:

答案 0 :(得分:3)

要回答我自己的问题,在@dursk评论问题可能与模块“请求”有关之后,我尝试再次更新它。我不确切知道为什么,但Pycharm没有更新这个模块。我尝试更新几次后,它已更新。现在它有效。

所以在Pycharm中转到设置&gt;项目&gt;项目口译员。在此列表中搜索您要查找的包,然后点击它。单击选项以下载特定版本并选择最新版本。然后只需单击“安装”即可完成