pythonpython-3.xsqlalchemychatterbotsite-packages

ImportError: cannot import name 'util' from partially initialized module 'sqlalchemy' (most likely due to a circular import)


I am using the ChatterBot library to create a chatbot and I have come across this error. I tried to create a chatbot object in my program but I get this compile time error

Traceback (most recent call last):
  File "d:\TwitterBot1\Bot1.py", line 123, in <module>
    bot = ChatBot('Bot1')
  File "D:\Python\lib\site-packages\chatterbot\chatterbot.py", line 34, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "D:\Python\lib\site-packages\chatterbot\utils.py", line 54, in initialize_class
    return Class(*args, **kwargs)
  File "D:\Python\lib\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
    from sqlalchemy import create_engine
  File "D:\Python\lib\site-packages\sqlalchemy\__init__.py", line 8, in <module>
    from . import util as _util  # noqa
ImportError: cannot import name 'util' from partially initialized module 'sqlalchemy' (most likely due to a circular import) (D:\Python\lib\site-packages\sqlalchemy\__init__.py)

I looked into the file that is in the error and the issue is with this import line

from . import util as _util  # noqa

and when I try running the __init__.py file, I get this error

Traceback (most recent call last):
  File "d:\Python\Lib\site-packages\sqlalchemy\__init__.py", line 8, in <module>
    from . import util as _util  # noqa
ImportError: attempted relative import with no known parent package

all of the other imports in the __init__.py file have some file directive of sorts after the "." following the "from" instruction. I am not sure if this file was missing some directive or what.

Can anyone point me in the direction of a fix?


Solution

  • I figured this out. Turns out that sqlalchemy 1.4(verson of this time) is not compatible with the current version of chatterbot so I deleted and reinstalled sqlalchemy with version 1.2. Then there was a time.clock error in one of the files in sqlalchemy so I replaced that with time.perf_counter() and everything works now