Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';模块';对象没有属性';包装';Pycharm 5.0.1_Python_Python 3.x_Pycharm - Fatal编程技术网

Python 属性错误:';模块';对象没有属性';包装';Pycharm 5.0.1

Python 属性错误:';模块';对象没有属性';包装';Pycharm 5.0.1,python,python-3.x,pycharm,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, 'r

我正在尝试制作一个简单的电报机器人,只发送一些文本回来。我和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)
导入时间
进口电传机
def添加(聊天室id,消息):
bot.sendMessage(聊天室id“添加”)
def年龄(聊天室id,msg):
bot.sendMessage(聊天室id,“年龄”)
def删除(聊天室id,消息):
bot.sendMessage(聊天室id“删除”)
def生日(聊天室id,msg):
bot.sendMessage(聊天室id,“生日”)
def句柄(msg):
chat_id=msg['chat']['id']
command=msg['text']
打印('获取命令:%s'%1!'
打印(聊天室id)
如果命令中有“/birth”:
生日(聊天室id,msg)
elif'/add'in命令:
添加(聊天室id,msg)
命令中的elif“/remove”:
删除(聊天室id,msg)
命令中的elif“/age”:
年龄(聊天室id,msg)
bot=telepot.bot(“”)
bot.notifyOnMessage(句柄)
打印('我在听…')
而1:
时间。睡眠(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
/usr/bin/python3.4/home/omer/pycharm项目/RelAgeBot/RelAgeBot.py
回溯(最近一次呼叫最后一次):
文件“/home/omer/PycharmProjects/RelAgeBot/RelAgeBot.py”,第17行,在
进口电传机
文件“/usr/local/lib/python3.4/dist-packages/telepot/_init__;u.py”,第17行,在
requests.packages.urllib3.disable_warnings()
AttributeError:“模块”对象没有属性“包”
进程已完成,退出代码为1

我已经在终端上安装了带有pip的“telepot”软件包,并再次安装了Pycharm,但它似乎不起作用。

为了回答我自己的问题,在@dursk评论问题可能与模块“请求”有关后,我尝试再次更新它。我不知道确切原因,但Pycharm没有更新此模块。在我尝试更新了几次之后,它被更新了。现在它起作用了


因此,在Pycharm中,进入设置>项目>项目解释器。在此列表中搜索您要查找的软件包,然后单击它。单击该选项下载特定版本并选择最新版本。然后只需单击“安装”即可完成

您是否有一个名为
请求
的模块,当它试图导入真正的
请求时,该模块可能与
telepot
发生冲突?@dursk是的,有一个名为请求的模块!我试过几次更新它,但我想我在什么地方失败了。在我成功地更新了请求之后,它工作了。谢谢,我会写一个答案:)但是你怎么知道是那个包裹?我看到模块请求出了问题,但我不明白为什么。@OmerSaker好吧,在stacktrace中,它爆炸的最后一行是在文件
/usr/local/lib/python3.4/dist packages/telepot/\uu init\uuuuuuuuuuy
中,所以我在这里查看了源代码:为了验证
telepot
包是否使用了
requests
@dursk谢谢,我以后会更仔细地查看堆栈跟踪。哇,同一行给了我一个问题:
requests.packages.urllib3.disable\u warnings()
我只是按照建议升级了
请求
包。我在Ubuntu的命令行中运行。我安装了sudopip3——升级请求,它解决了我的问题。谢谢