How to fix AttributeError: partially initialized module ‘pandas’ has no attribute ‘DataFrame’ (most likely due to a circular import)

In this post I will show you how to solve AttributeError: partially initialized module ‘pandas’ has no attribute ‘DataFrame’ (most likely due to a circular import).

The full stack of the error is:

Traceback (most recent call last):
  File "C:\Users\panda\PycharmProjects\venv\pandas.py", line 1, in 
    import pandas as pd
  File "C:\Users\panda\PycharmProjects\venv\pandas.py", line 3, in 
    print(pd.__version__)
AttributeError: partially initialized module 'pandas' has no attribute '__version__' (most likely due to a circular import)

Process finished with exit code 1

How to fix partially initialized module ‘pandas’ has no attribute

You can find out the cause of the error in the full text of the error, although it is not obvious.

Pandas doesn’t like the filename pandas.py. This is where circular import comes in.

Error solution: rename the file to something else, e.g. my_file.py.

A similar problem may occur with other Python modules.

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

Don’t name files in a way that might confuse Python. In particular, do not include module or function names in filenames.

This Post Has One Comment

Leave a Reply