AttributeError: partially initialized module has no attribute…(Python)

Python AttributeError: partially initialized module

Less of a blog post and more of a reminder to myself that when Python says:

AttributeError: partially initialized module 'MODULE_NAME' has no attribute 'ATTRIBUTE_NAME' (most likely due to a circular import)

It is normally because I have named my Python file the same as the module I am importing and caused a circular reference. In this case I am looking at using the Python logging module and saved my Python file as logging.py, so when I then imported logging and tried to call on its functions it failed.

Python AttributeError: partially initialized module
Python AttributeError: partially initialized module

The solution is not to name the Python file the same as any of the modules being imported in that Python file.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.