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

Viewed 19

I'm trying to make a simple program using the pathlib directory, but every time I try to run it I get this error. I already tried uninstalling and reinstalling Path.py and pathlib itself. Nothing seems to work.

import pathlib


path = pathlib.Path('ecommerce')
print(path.exists())

Here's the code if anybody needs it, but as I said, I just wanted to try out this module and the program itself doesn't do anything.

Also, here's the entire log:

Traceback (most recent call last):
  File "C:\Users\Dave\Desktop\Programming\Python\pathlib.py", line 1, in <module>
    import pathlib
  File "C:\Users\Dave\Desktop\Programming\Python\pathlib.py", line 4, in <module>
    path = pathlib.Path('ecommerce')
AttributeError: partially initialized module 'pathlib' has no attribute 'Path' (most likely due to a circular import)
1 Answers

Python is being confused about what pathlib you're talking about.

Don't name your own program pathlib, or any other module name in the standard library for that matter.

This also stands even if you're not directly importing the module - if some other module would attempt to import pathlib, there'd be the same conflict.

Related