0

I have written code to create a ChatBot using HTML & python. I used python 3.8 but it fails when I tried to execute the form. I don't know how it fails because I used the latest version of python. I also tried some solutions published, but they also didn't work for me well. Help me with some solutions.

Here's the Code:

app.py


    #import files
    from flask import Flask, render_template, request
    from chatterbot import ChatBot
    from chatterbot.trainers import ChatterBotCorpusTrainer
    from chatterbot.trainers import ListTrainer

    app = Flask(__name__)

    bot = ChatBot("Python-BOT")

    trainer = ListTrainer(bot)
    trainer.train(['what is your name?', 'My name is Python-BOT'])
    trainer.train(['who are you?', 'I am a BOT'])

    trainer = ChatterBotCorpusTrainer(bot)
    trainer.train("chatterbot.corpus.english")


    @app.route("/")
    def index():
        return render_template('index.html')


    @app.route("/get")
    def get_bot_response():
        userText = request.args.get('msg')
        return str(bot.get_response(userText))


    if __name__ == "__main__":
        app.run()


index.html


    <!DOCTYPE html>
    <html>
      <head>
        <title>Python-BOT</title>
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <style>
          * {
            box-sizing: border-box;
          }
          body,
          html {
            height: 100%;
            margin: 0;
            font-family: Arial, Helvetica, sans-serif;
          }
          #chatbox {
            margin-left: auto;
            margin-right: auto;
            width: 40%;
            margin-top: 60px;
          }
          #userInput {
            margin-left: auto;
            margin-right: auto;
            width: 40%;
            margin-top: 60px;
          }
          #textInput {
            width: 90%;
            border: none;
            border-bottom: 3px solid black;
            font-family: monospace;
            font-size: 17px;
          }
          .userText {
            color: white;
            font-family: monospace;
            font-size: 17px;
            text-align: right;
            line-height: 30px;
          }
          .userText span {
            background-color: #808080;
            padding: 10px;
            border-radius: 2px;
          }
          .botText {
            color: white;
            font-family: monospace;
            font-size: 17px;
            text-align: left;
            line-height: 30px;
          }
          .botText span {
            background-color: #4169e1;
            padding: 10px;
            border-radius: 2px;
          }
          #tidbit {
            position: absolute;
            bottom: 0;
            right: 0;
            width: 300px;
          }
          .boxed {
            margin-left: auto;
            margin-right: auto;
            width: 78%;
            margin-top: 60px;
            border: 1px solid green;
          }
        </style>
      </head>
      <body>
        <div>
          <h1 align="center">
            <b>Welcome to Python-BOT</b>
          </h1>
        </div>
      </body>
    </html>


And this is the error I got when I tried to execute the result in Python 3.8 version


    F:\Projects\python_projects\ChatBot-sample-3>"F:/Installed Software/python/phython 3.8/python.exe" f:/Projects/python_projects/ChatBot-sample-3/app.py   
    Traceback (most recent call last):
      File "f:/Projects/python_projects/ChatBot-sample-3/app.py", line 9, in <module>
        bot = ChatBot("Python-BOT")
      File "C:\Users\AMASHI SANDUNIKA\AppData\Roaming\Python\Python38\site-packages\chatterbot\chatterbot.py", line 34, in __init__
        self.storage = utils.initialize_class(storage_adapter, **kwargs)
      File "C:\Users\AMASHI SANDUNIKA\AppData\Roaming\Python\Python38\site-packages\chatterbot\utils.py", line 54, in initialize_class
        return Class(*args, **kwargs)
      File "C:\Users\AMASHI SANDUNIKA\AppData\Roaming\Python\Python38\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
        from sqlalchemy import create_engine
      File "C:\Users\AMASHI SANDUNIKA\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\__init__.py", line 8, in <module>
        from . import util as _util  # noqa
      File "C:\Users\AMASHI SANDUNIKA\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
        from ._collections import coerce_generator_arg  # noqa
      File "C:\Users\AMASHI SANDUNIKA\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
        from .compat import binary_types
      File "C:\Users\AMASHI SANDUNIKA\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
        time_func = time.clock
    AttributeError: module 'time' has no attribute 'clock'

Yosef Tukachinsky
  • 5,570
  • 1
  • 13
  • 29
Amashi S.
  • 13
  • 1
  • 4
  • 1
    Your issue was already reported and answered [here](https://stackoverflow.com/questions/62436786/attributeerror-module-time-has-no-attribute-clock-in-sqlalchemy-python-3-8). – Erme Schultz Jun 27 '20 at 11:23
  • Does this answer your question? [AttributeError: module 'time' has no attribute 'clock' In SQLAlchemy python 3.8.2](https://stackoverflow.com/questions/62436786/attributeerror-module-time-has-no-attribute-clock-in-sqlalchemy-python-3-8) – urban Jun 27 '20 at 11:39

2 Answers2

0

The error occurs because in python 2, there is time.clock(), but in python 3, it has been replaced with time.perf_counter().

Just replace all the time.clock to time.perf_counter, and it should be fine. For more info: https://www.webucator.com/blog/2015/08/python-clocks-explained/

From https://stackoverflow.com/a/62436862/11912082

Nobert
  • 163
  • 1
  • 16
-1

try this it worked for me:

if win32 or jython:
    try: # Python 3.4+
        preferred_clock = time.perf_counter
    except AttributeError: # Earlier than Python 3.
        preferred_clock = time.clock
else:
    time_func = time.time
Nico Albers
  • 1,556
  • 1
  • 15
  • 32