Problems with python libraries, Chatbot

Asked

Viewed 1,424 times

2

I’m having trouble with the Python library, specifically the Chatbot, the error is as follows:

from chatterbot import Chatbot
ImportError: cannot import name 'Chatbot' "

Here is my code:

from chatterbot import Chatbot
import pyttsx
import speech_recognition as sr

en = pyttsx.init()
en.setProperty('voice',b'brazil')
rec = sr.Recognizer()

class BotFalante(Chatbot):
    def escuta(self,frase=None):
        try:
            with sr.Microphone() as mic:
                fala = rec.listen(mic)
            frase = rec.recognize_google(fala,language='pt')
            frase = frase.replace('aprendi','aprende')
            print(frase)
        except sr.UnknownValueError:
            print('Deu erro na identificação')
            return ('')
        return super().escuta(frase=frase)

    def fala(self,frase):
        en.say(frase)
        en.runAndWait()
        super().fala(frase)

Bot = BotFalante('Zuleide')
while True:
    frase = Bot.escuta()
    resp = Bot.pensa(frase)
    Bot.fala(resp)
    if resp == ('falou'):

        break
  • Have you installed chatbot? with Pip install chatterbot ? Take a look here: https://chatterbot.readthedocs.io/en/stable/tutorial.html

  • i installed with sudo pip3 install chatterbot (Ubuntu use)

  • because it checks if it is installed python -m chatterbot --version. If it is not and uses umbunto it uses the command. pip3 install git+git://github.com/gunthercox/Chatterbot.git@master

  • when I give the command python -m chatterbot --version. , back it up: /usr/bin/python: In the module named chatterbot, even if I already installed the same

  • then the module is not installed. A tip I can give to help you. Installs Anaconda in unbuntu. You will avoid these installation and release problems. https://www.anaconda.com/download/#linux

2 answers

0

You named your chatterbot chatterbot.py and then imported the chatterbot changes its name to any other and should work.

  • I changed the file name and did nothing :/

  • 1

    you have to also delete the chatterbot.pyc that was generated

0

Wherever Chatbot mute to ChatBot:

from chatterbot import ChatBot

class BotFalante(ChatBot):

Browser other questions tagged

You are not signed in. Login or sign up in order to post.