gunthercox / ChatterBot

ChatterBot is a machine learning, conversational dialog engine for creating chat bots
https://chatterbot.readthedocs.io
BSD 3-Clause "New" or "Revised" License
14.06k stars 4.44k forks source link

AttributeError: module 'time' has no attribute 'clock' #1968

Closed SergioLopezJAAS closed 4 years ago

SergioLopezJAAS commented 4 years ago

Code Source:

`from chatterbot import ChatBot chatbot = ChatBot( 'EjemploBot', trainer='chatterbot.trainers.ChatterBotCorpusTrainer' )

chatbot.train("chatterbot.corpus.spanish")

while True: usuario = input(">>> ") respuesta = chatbot.get_response(usuario) print ("bot: "+str(respuesta))

`

ERROR:

C:\00-Documentos\01-Proyectos\01-Proyectos Python\01-Chatbot>python pract_chatterbox_v2.py Traceback (most recent call last): File "pract_chatterbox_v2.py", line 5, in chatbot = ChatBot( File "C:\Python38-64\lib\site-packages\chatterbot\chatterbot.py", line 35, in init self.storage = utils.initialize_class(storage_adapter, *kwargs) File "C:\Python38-64\lib\site-packages\chatterbot\utils.py", line 54, in initialize_class return Class(args, **kwargs) File "C:\Python38-64\lib\site-packages\chatterbot\storage\sql_storage.py", line 22, in init from sqlalchemy import create_engine File "C:\Python38-64\lib\site-packages\sqlalchemy__init__.py", line 8, in from . import util as _util # noqa File "C:\Python38-64\lib\site-packages\sqlalchemy\util__init__.py", line 14, in from ._collections import coerce_generator_arg # noqa File "C:\Python38-64\lib\site-packages\sqlalchemy\util_collections.py", line 16, in from .compat import binary_types File "C:\Python38-64\lib\site-packages\sqlalchemy\util\compat.py", line 264, in time_func = time.clock AttributeError: module 'time' has no attribute 'clock'

``

supremenerd88 commented 4 years ago

me too.

i think that the problem is this control:

if win32 or jython: time_func = time.clock else: time_func = time.time

file compat.py (SQLAlchemy library). the control is not correct. it may be:

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

like sessions.py (requests library)

(sorry for bad indentations, but i don't know how to indent in comment...)

gunthercox commented 4 years ago

Thank you for using Python 3.8. I haven't gotten around to testing ChatterBot out with that version of Python yet but I'm a huge fan of some of the improvements they made in that version. I will attempt to add compatibility soon.

PriyamTongia commented 4 years ago

I'm also facing the same problem and hope to see updates soon but think the solution: 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

is working properly!!

gunthercox commented 4 years ago

I just released version 1.0.7 of ChatterBot which should contain changes that resolved this issue.

E-David5 commented 4 years ago

How can i install version 1.0.7?

gunthercox commented 4 years ago

There are a few ways to install it. For example, this will install the latest version:

pip3 install chatterbot --upgrade
ghost commented 3 years ago

Whenever I try to install 1.0.7, I get: ERROR: Command errored out with exit status 1: And then a lot of red text

thewasta commented 3 years ago

Whenever I try to install 1.0.7, I get: ERROR: Command errored out with exit status 1: And then a lot of red text

Try with Python 3.7

InfernalPlank commented 3 years ago

There are a few ways to install it. For example, this will install the latest version:

pip3 install chatterbot --upgrade

@gunthercox Working on some interesting implementations with your library here, thanks for making your work public! I'm having some issues specifically as stated in #1986 . Doing as you said above yields the same issues on Windows 10 with Python 3.8.2. See here:

File "scriptName.py", line 83, in startChatbot
    bot = ChatBot("botName")
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\chatterbot\chatterbot.py", line 34, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\chatterbot\utils.py", line 47, in initialize_class
    return Class(*args, **kwargs)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
    from sqlalchemy import create_engine
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 8, in <module>
    from . import util as _util  # noqa
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
    from ._collections import coerce_generator_arg  # noqa
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
    from .compat import binary_types
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
    time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
InfernalPlank commented 3 years ago

Update: Got it working. Followed the advice as prescribed in #2029 and #2039 managed to solve my issues! Thanks guys.

kothawleprem commented 3 years ago

I just commented the block of code causing error, i.e. line 264 in compat.py and its working fine.

Ai-Ivy commented 3 years ago

WARNING: Discarding https://files.pythonhosted.org/packages/ce/5e/8f21b3f32ea3566764d1c90f4360703be7d1739ed7b51cbf89bed00fa331/spacy-2.1.0.tar.gz#sha256=e3dbde5b560fb9dd3706bd6838e66e28119b6aa17bcb0711d53e95c830bcf0a7 (from https://pypi.org/simple/spacy/) (requires-python:>=2.7,!=3.0.,!=3.1.,!=3.2.,!=3.3.). Command errored out with exit status 1: 'c:\users\darks\appdata\local\programs\python\python39\python.exe' 'C:\Users\darks\AppData\Roaming\Python\Python39\site-packages\pip' install --ignore-installed --no-user --prefix 'C:\Users\darks\AppData\Local\Temp\pip-build-env-39zl9vvx\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools 'wheel>0.32.0.<0.33.0' Cython 'cymem>=2.0.2,<2.1.0' 'preshed>=2.0.1,<2.1.0' 'murmurhash>=0.28.0,<1.1.0' thinc==7.0.0.dev6 Check the logs for full command output. ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'c:\users\darks\appdata\local\programs\python\python39\lib\site-packages\ChatterBot-1.0.4.dist-info\METADATA'

judmesa commented 2 years ago

I am having the same problem with the last version, what can I do?

from sqlalchemy import create_engine

File "C:\Users\Juan Camilo\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy__init__.py", line 8, in from . import util as _util # noqa File "C:\Users\Juan Camilo\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\util__init__.py", line 14, in
from ._collections import coerce_generator_arg # noqa File "C:\Users\Juan Camilo\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\util_collections.py", line 16, in from .compat import binary_types File "C:\Users\Juan Camilo\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\util\compat.py", line 264, in
time_func = time.clock AttributeError: module 'time' has no attribute 'clock' PS C:\Users\Juan Camilo\Documents\ALEC>

GuhOliv commented 1 year ago

me too.

i think that the problem is this control:

if win32 or jython: time_func = time.clock else: time_func = time.time

file compat.py (SQLAlchemy library). the control is not correct. it may be:

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

like sessions.py (requests library)

(sorry for bad indentations, but i don't know how to indent in comment...)

Thank you very much

SHADOW-2210 commented 5 months ago

The bellow is my code:

from chatterbot import ChatBot from chatterbot.trainers import ChatterBotCorpusTrainer from chatterbot.trainers import ListTrainer import time time.clock = time.time

chatbot = ChatBot('My ChatBot') trainer = ChatterBotCorpusTrainer(chatbot) trainer.train("chatterbot.corpus.english.greetings", "chatterbot.corpus.english.conversation")

trainer.train([ "How are you?", "I am good.", "That is good to hear.", "Thank you", "You're welcome.", ])

def add_training_data(conversation): trainer = ListTrainer(chatbot) trainer.train(conversation)

while True: user_input= input("user:") if user_input== "exit": break else: response= chatbot.get_response(user_input) print("bot:", response)

(this shows the error below)

[nltk_data] Downloading package averaged_perceptron_tagger to [nltk_data] C:\Users\Anurag Chanda\AppData\Roaming\nltk_data... [nltk_data] Package averaged_perceptron_tagger is already up-to- [nltk_data] date! [nltk_data] Downloading package punkt to C:\Users\Anurag [nltk_data] Chanda\AppData\Roaming\nltk_data... [nltk_data] Package punkt is already up-to-date! [nltk_data] Downloading package stopwords to C:\Users\Anurag [nltk_data] Chanda\AppData\Roaming\nltk_data... [nltk_data] Package stopwords is already up-to-date! Traceback (most recent call last): File "d:\code\tempCodeRunnerFile.py", line 9, in trainer.train("chatterbot.corpus.english.greetings") File "C:\Users\Anurag Chanda\AppData\Local\Programs\Python\Python312\Lib\site-packages\chatterbot\trainers.py", line 138, in train for corpus, categories, file_path in load_corpus(*data_file_paths): File "C:\Users\Anurag Chanda\AppData\Local\Programs\Python\Python312\Lib\site-packages\chatterbot\corpus.py", line 63, in load_corpus corpus_data = read_corpus(file_path) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Anurag Chanda\AppData\Local\Programs\Python\Python312\Lib\site-packages\chatterbot\corpus.py", line 38, in read_corpus return yaml.load(data_file) ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Anurag Chanda\AppData\Local\Programs\Python\Python312\Lib\site-packages\yaml__init__.py", line 72, in load return loader.get_single_data() ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Anurag Chanda\AppData\Local\Programs\Python\Python312\Lib\site-packages\yaml\constructor.py", line 37, in get_single_data return self.construct_document(node) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Anurag Chanda\AppData\Local\Programs\Python\Python312\Lib\site-packages\yaml\constructor.py", line 46, in construct_document for dummy in generator: File "C:\Users\Anurag Chanda\AppData\Local\Programs\Python\Python312\Lib\site-packages\yaml\constructor.py", line 398, in construct_yaml_map value = self.construct_mapping(node) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Anurag Chanda\AppData\Local\Programs\Python\Python312\Lib\site-packages\yaml\constructor.py", line 204, in construct_mapping return super().construct_mapping(node, deep=deep) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Anurag Chanda\AppData\Local\Programs\Python\Python312\Lib\site-packages\yaml\constructor.py", line 126, in construct_mapping if not isinstance(key, collections.Hashable): ^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'collections' has no attribute 'Hashable'

Can any one help me out with this?