1

I installed chatterbot in my terminal earlier today using virtual studio code's terminal. I saw that both chatterbot and chatterbot_corpus worked in installation. Then, I made the following python document:

EDIT: Turns out I should define a chatbot variable first.

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

conversation = [
    "Hello",
    "Hi there!",
    "How are you doing?",
    "I'm doing great.",
    "That is good to hear",
    "Thank you.",
    "You're welcome."
]
bot = ChatBot('Maya')
trainer = ListTrainer(bot)

trainer.train(conversation)

This was my code

it says this however

bot = ChatBot('Maya')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
    return Class(*args, **kwargs)
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
    from sqlalchemy import create_engine
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\__init__.py", line 8, in <module>
    from . import util as _util  # noqa
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
    from ._collections import coerce_generator_arg  # noqa
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
    from .compat import binary_types
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
    time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'

Does anyone know how to fix this easily?

EDIT: I just updated python using pip install --upgrade ipython in terminal, but it didn't fix the issue

EDIT 2: Well now I tried updating a package using pip install sqlalchemy --upgrade

But now it gives

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
    return Class(*args, **kwargs)
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 46, in __init__
    if not self.engine.dialect.has_table(self.engine, 'Statement'):
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\dialects\sqlite\base.py", line 2009, in has_table
    self._ensure_has_table_connection(connection)
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\engine\default.py", line 341, in _ensure_has_table_connection
    raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: The argument passed to Dialect.has_table() should be a <class 'sqlalchemy.engine.base.Connection'>, 
got <class 'sqlalchemy.engine.base.Engine'>. Additionally, the Dialect.has_table() method is for internal dialect use only; please use ``inspect(some_engine).has_table(<tablename>>)`` for public API use.

I am in the latest version though

PS C:\Users\Subha> Python --version
Python 3.9.6

EDIT 3: Now it comes up with

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
    return Class(*args, **kwargs)
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 46, in __init__       
    # if not self.engine.dialect.has_table(self.engine, 'Statement'):
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\dialects\sqlite\base.py", line 2009, in has_table
    self._ensure_has_table_connection(connection)
  File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\engine\default.py", line 341, in _ensure_has_table_connection
    raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: The argument passed to Dialect.has_table() should be a <class 'sqlalchemy.engine.base.Connection'>, got <class 'sqlalchemy.engine.base.Engine'>. Additionally, the Dialect.has_table() method is for internal dialect use only; please use ``inspect(some_engine).has_table(<tablename>>)`` for public API use.
sparkles
  • 11
  • 2
  • the issue is solved here: https://github.com/gunthercox/ChatterBot/issues/1586 – Olasimbo Jul 21 '21 at 20:12
  • Sorry, I did check that out, but it doesn't solve my problem. I will edit my question – sparkles Jul 21 '21 at 20:13
  • probably your Python version. how about this: https://stackoverflow.com/questions/58569361/attributeerror-module-time-has-no-attribute-clock-in-python-3-8 – Olasimbo Jul 21 '21 at 20:27
  • Yeah, I just looked at that but I can't figure out how to get rid of time.clock like they suggested. I did update python, etc. though – sparkles Jul 21 '21 at 20:32

2 Answers2

0

it seems the python upgrade worked with regard to the initial error on time.clock. This new error you are seeing is quite different to the previous one. In this case you need to go into chatterbot/storage/sql_storage.py and comment out if not self.engine.dialect.has_table(self.engine, 'Statement'): and leave only self.create_database(). This means that instead of checking whether a database table has been created which is triggering the error, it will just create the DB every time, which i expect to work fine.

# if not self.engine.dialect.has_table(self.engine, 'Statement'):
self.create_database()
Olasimbo
  • 965
  • 6
  • 14
0
  1. Try getting the github files and put it into a folder of your choice. Make sure to run the setup.py
  2. Make sure to have nltk installed
  3. If you don't have chatterbot installed using the pip, then do it.

I did this and the error left. I'm also on Windows 11 and everything is updated.