简体   繁体   English

无法在 python 中导入聊天机器人

[英]unable to import chatterbot in python

python app.py python app.py

Traceback (most recent call last):
  File "app.py", line 1, in <module>
    from chatbot import chatbot
  File "C:\Users\hp\Desktop\try_projects\chat_bot\chatbot.py", line 1, in <module>
    from chatterbot import ChatBot
ModuleNotFoundError: No module named 'chatterbot'

Code is代码是

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer, ChatterBotCorpusTrainer
 

chatbot= ChatBot('Crazy')

what might be the solution to this problem?这个问题的解决方案可能是什么? python version: 3.8.3 python 版本:3.8.3

Try installing the previous version of ChatterBot.尝试安装以前版本的 ChatterBot。

pip install chatterbot==1.0.4

This should work, unless there are some other problems.这应该有效,除非有其他问题。 I had the same problem and it worked for me.我有同样的问题,它对我有用。

There would be another problem if you are using Python 3.8.x.如果您使用的是 Python 3.8.x,则会出现另一个问题。 In Python 3.8.x, a few functions of a few modules were removed.在 Python 3.8.x 中,删除了一些模块的一些功能。 You will be able to import ChattberBot, but when you name the bot, there will be an error.您将能够导入 ChattberBot,但是当您为机器人命名时,会出现错误。

 File "C:\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'

Copy the location for the file given in the last line, where the error occurs.复制最后一行中出现错误的文件的位置。

C:\Python38\lib\site-packages\sqlalchemy\util\compat.py

Open file with IDLE or whatever editor you have.使用 IDLE 或您拥有的任何编辑器打开文件。 Please do Not open the file directly(this will run the file, and you will not be able to see the code), instead Open with IDLE or Your Text editor Then, go to line 264 in that.请不要直接打开文件(这将运行文件,您将无法看到代码),而是使用 IDLE 或您的文本编辑器打开然后,go 到第 264 行。 It would be written会写成

time_func = time.clock

Instead of this change it to而不是这个改变它

time_func = time.perf_counter()

I Hope this helped!我希望这有帮助! This was my first answer on StackOverflow !这是我在 StackOverflow 上的第一个答案!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM