ImportError:使用chatterbot时没有名为db的模块

Jer*_*ews 2 python python-2.7 chatterbot

我正在尝试建立一个聊天机器人.所以我安装了chatterbot包.python代码如下:

from chatterbot import TalkWithCleverbot
talk = TalkWithCleverbot()
talk.begin()
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

 Traceback (most recent call last):
 File "C:\Users\JERIN\Desktop\bottobot.py", line 2, in <module>
   talk = TalkWithCleverbot()
 File "C:\Python27\lib\site-packages\chatterbot\__init__.py", line 157, in     __init__
 super(TalkWithCleverbot, self).__init__()
 File "C:\Python27\lib\site-packages\chatterbot\__init__.py", line 4, in  __init__
 from jsondb.db import Database
 ImportError: No module named db
Run Code Online (Sandbox Code Playgroud)

我尝试安装jsondb和db软件包,但没有好处.请帮我

小智 7

您的错误突出显示了问题 - 没有db要从jsondb中导入的对象__init__.py.

def __init__(self, name="bot", logging=True):
      from jsondb.db import Database
                  ^^ this doesn't exist
Run Code Online (Sandbox Code Playgroud)

在GitHub上找到了'ChatterBot '模块的源代码,看来作者导入的'jsondb'不是你从pip安装时获得的'jsondb' .相反,作者希望您使用可以在GitHub上找到的他的 jsondb模块.

您可以通过卸载从pip中检索到的jsondb来解决此问题:

pip uninstall jsondb
Run Code Online (Sandbox Code Playgroud)

并安装ChatterBot作者的jsondb模块:

pip install git+https://github.com/gunthercox/jsondb.git
Run Code Online (Sandbox Code Playgroud)

您遇到此错误是因为ChatterBot作者假设您安装名为jsondb的软件包,并且没有以典型方式包含依赖项.