'Installed chatbot but getting Error while importing ChatBot

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os

bot = ChatBot('Bot')
bot.set_trainer(ListTrainer)

for files in os.listdir('D:/Anaconda3/Lib/site-packages/chatterbot_corpus/data/english'):
    data = open('D:/Anaconda3/Lib/site-packages/chatterbot_corpus/data/english' + files, 'r').readlines()
    bot.train(data)
while True:
    message = input('You')
    if message.strip() != 'Bye':

        reply = bot.get_response(message)
        print('ChatBot :', reply)
    if message.strip() == 'Bye':
        print('ChatBot : Bye')
        break  

I'm getting an error:

Traceback (most recent call last): File "C:\Users\nakulmagotra\Desktop\chatbot_train.py", line 1, in from chatterbot import ChatBot ModuleNotFoundError: No module named 'chatterbot'

I'm a complete noob to Chatterbot . Thanks.



Solution 1:[1]

According to this, you should install it by pip install chatterbot or setup manually with git clone https://github.com/gunthercox/ChatterBot and into the cloned directory run python setup.py install. After that, you can simply check it by using import chatterbot and see if it showing error or not.

Solution 2:[2]

This Error Maybe due to Some reason.

  • chatter is not installed try pip install chatterbot
  • You are using a different environment. try to change the environment
  • chatterbot is not in the path

Solution 3:[3]

Try installing the previous version of 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 . In Python 3.8.x, a few functions of a few modules were removed. You will be able to import ChattberBot , but when you name the bot, there will be an error.

 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. 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 . It would be written

time_func = time.clock

Instead of this change it to

time_func = time.perf_counter()

Solution 4:[4]

Open terminal in pycharm Write pip install chatterbox Then one error may occur that time has no module clock To fix it Copy the location of last error Then open it on pycharm not open it directly Go in line no.264 And change it time clock() to time per_counter

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 CodePerfectPlus
Solution 3 Vishnu Joshi
Solution 4 Anshika Gupta