utils.initialize_class error when running a simple chatterbot script - python

I am learning and building a chatterbot with Python. I start with writing a simple chattbox. When I run the code, it errors out.
I am using Python 3.8.5, chatterbot 1.0.4 and Atom IDE
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot('Javis')
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train("chatterbot.corpus.english")
response = chatbot.get_response("Hello, how are you today?")
print(response)
When I run the code on Atom platformio-ide-terminal, it throws an error
Traceback (most recent call last):
File "chatbot.py", line 4, in <module>
chatbot = ChatBot('Bon')
File "C:\Python\Python38-32\lib\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Python\Python38-32\lib\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Python\Python38-32\lib\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
from sqlalchemy import create_engine
File "C:\Python\Python38-32\lib\site-packages\sqlalchemy\__init__.py", line 8, in <module>
from . import util as _util # noqa
File "C:\Python\Python38-32\lib\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
from ._collections import coerce_generator_arg # noqa
File "C:\Python\Python38-32\lib\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
from .compat import binary_types
File "C:\Python\Python38-32\lib\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'

The function time.clock is deprecated since 3.3 version of python. Please check here for reference AttributeError: module 'time' has no attribute 'clock' in Python 3.8 , might be useful.

Related

Getting multiple error while using flask-ask and ngrok with ROS

I'm trying to use flask-ask library and develope a skill that can make me able to control a robot in ROS with alexa vocal assistant. Python code named "alexa_interface.py" is here.
The skill id number is substituted with my skill id number.
While launching this command
python3 alexa_interface.py
I am getting the following code error.
Tried to install dependencies with pip but getting:
AttributeError: module 'lib' has no attribute 'ERR_load_RAND_strings'
Also notice that I am getting this error everytime I use pip to install something. Is pip broken? How can I adjust this?
Thank you.
#! /usr/bin/env python3
from flask import Flask
from ask_sdk_core.skill_builder import SkillBuilder
from flask_ask_sdk.skill_adapter import SkillAdapter
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.utils import is_request_type, is_intent_name
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model import Response
from ask_sdk_model.ui import SimpleCard
app = Flask(__name__)
class LaunchRequestHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_request_type("LaunchRequest")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "Ciao, come posso aiutarti?"
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response`
skill_builder = SkillBuilder()
# Register your intent handlers to the skill_builder object
skill_builder.add_request_handler(LaunchRequestHandler())
skill_adapter = SkillAdapter(
skill=skill_builder.create(), skill_id="my-skill-id", app=app)
skill_adapter.register(app=app, route="/")
if __name__=='__main__':
app.run()
```
```
Traceback (most recent call last):
File "alexa_interface.py", line 2, in <module>
from flask import Flask
File "/home/toti/.local/lib/python3.8/site-packages/flask/__init__.py", line 14, in <module>
from jinja2 import escape
ImportError: cannot import name 'escape' from 'jinja2' (/home/toti/.local/lib/python3.8/site-packages/jinja2/__init__.py)
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 32, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 12, in <module>
import os, glob, subprocess, os.path, time, pwd, sys, requests_unixsocket
File "/usr/lib/python3/dist-packages/requests_unixsocket/__init__.py", line 1, in <module>
import requests
File "/home/toti/.local/lib/python3.8/site-packages/requests/__init__.py", line 52, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/home/toti/.local/lib/python3.8/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/home/toti/.local/lib/python3.8/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/home/toti/.local/lib/python3.8/site-packages/OpenSSL/rand.py", line 213, in <module>
_lib.ERR_load_RAND_strings()
AttributeError: module 'lib' has no attribute 'ERR_load_RAND_strings'
Original exception was:
Traceback (most recent call last):
File "alexa_interface.py", line 2, in <module>
from flask import Flask
File "/home/toti/.local/lib/python3.8/site-packages/flask/__init__.py", line 14, in <module>
from jinja2 import escape
ImportError: cannot import name 'escape' from 'jinja2' (/home/toti/.local/lib/python3.8/site-packages/jinja2/__init__.py)
```

Chatterbot Attribute error. ChatBot object has no Attribute find

I am trying to make a chatbot with Chatterbot, Python.
I have the following code.
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot('Ron Obvious')
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train("chatterbot.corpus.english")
r = chatbot.get_response("Hello, how are you today?")
print(r)
When ever I run it, it shows me the following error message.
ai.yml Training: [ ] 1%Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "<string>", line 7, in <module>
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/chatterbot/trainers.py", line 159, in train
statement = self.get_or_create(text)
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/chatterbot/trainers.py", line 48, in get_or_create
statement = self.storage.find(temp_statement.text)
AttributeError: 'ChatBot' object has no attribute 'find'
How to fix this?

Checkov error: AttributeError: type object 'Lark' has no attribute '_load_from_dict

I'm having some issues running checkov, I'm not familiar with python libraries, anyone can give me some hints?
This is working fine in some machines but not in this one in particular...
Running in CentOS:
$ checkov --directory cdk.out
Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in <module>
from checkov.main import run
File "/usr/local/lib/python3.6/site-packages/checkov/main.py", line 22, in <module>
from checkov.terraform.plan_runner import Runner as tf_plan_runner
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/plan_runner.py", line 11, in <module>
from checkov.terraform.context_parsers.registry import parser_registry
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/context_parsers/__init__.py", line 1, in <module>
from checkov.terraform.context_parsers.parsers import *
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/context_parsers/parsers/provider_context_parser.py", line 1, in <module>
import hcl2
File "/usr/local/lib/python3.6/site-packages/hcl2/__init__.py", line 5, in <module>
from .api import load, loads
File "/usr/local/lib/python3.6/site-packages/hcl2/api.py", line 4, in <module>
from hcl2.parser import hcl2
File "/usr/local/lib/python3.6/site-packages/hcl2/parser.py", line 53, in <module>
hcl2 = Lark_StandAlone(transformer=DictTransformer())
File "/usr/local/lib/python3.6/site-packages/hcl2/lark_parser.py", line 8, in Lark_StandAlone
return Lark._load_from_dict(DATA, MEMO, **kwargs)
AttributeError: type object 'Lark' has no attribute '_load_from_dict'
After upgrading python from 3.6 to 3.8 and reinstalling checkov it worked just fine.

AttributeError: module 'time' has no attribute 'clock' In SQLAlchemy python 3.8.2

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Anirudh\Documents\flask_app\connecting_to_database\application.py", line 2, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 18, in <module>
import sqlalchemy
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
from .sql import (
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
from .expression import (
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
from .visitors import Visitable
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
from .. import util
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
from .compat import callable, cmp, reduce, \
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 234, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
I had this issue with SQLAlchemy 1.2.10. Upgrading to the current version (1.3.18 as of now) fixed the problem
pip install sqlalchemy --upgrade
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/
I found a solution that worked for me
I have a virtual environment carpet named env in which I installed sqlalchemy
So, env\Lib\site-packages\flask_sqlalchemy_init_.py
Inside that there is this code:
if sys.platform == 'win32':
_timer = time.clock
else:
_timer = time.time
And I changed clock to perf_counter()
_timer = time.perf_counter()

import shapely.geometry throws AttributeError: function 'GEOSversion' not found

import shapely.geometry works fine in the interpreter but the code throws this error when running:
AttributeError: function 'GEOSversion' not found
Also tried
import geos
ImportError: No module named geos`
But Shapely used to run perfectly.
Have not found any post regarding this problem in SO. Any help is much appreciated. Thanks!
Shapely‑1.3.2.win‑amd64‑py2.7.exe installed from this link which is supposed to include GEOS dependencies.
Python 2.7 64bit Anaconda on Win7 64bit. Using Eclipse with PyDev
Traceback (most recent call last):
File "C:\...\file.py", line 3, in <module>
import shapely.geometry
File "C:\Users\AppData\Local\Continuum\Anaconda\lib\site-packages\shapely\geometry\__init__.py", line 4, in <module>
from .base import CAP_STYLE, JOIN_STYLE
File "C:\Users\AppData\Local\Continuum\Anaconda\lib\site-packages\shapely\geometry\base.py", line 9, in <module>
from shapely.coords import CoordinateSequence
File "C:\Users\AppData\Local\Continuum\Anaconda\lib\site-packages\shapely\coords.py", line 8, in <module>
from shapely.geos import lgeos
File "C:\Users\AppData\Local\Continuum\Anaconda\lib\site-packages\shapely\geos.py", line 125, in <module>
geos_version_string, geos_version, geos_capi_version = _geos_version()
File "C:\Users\AppData\Local\Continuum\Anaconda\lib\site- packages\shapely\geos.py", line 112, in _geos_version
GEOSversion = _lgeos.GEOSversion
File "C:\Users\AppData\Local\Continuum\Anaconda\lib\ctypes\__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "C:\Users\AppData\Local\Continuum\Anaconda\lib\ctypes\__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'GEOSversion' not found

Categories