Search code examples
python-3.xpandasnumpypippackage

inspect.py file in folder makes importing pandas not work anymore


I am sorry if this is a silly question but I came across a wierd behaviour. I have a folder with some files, one of them named inspect.py enter image description here

However, if I change the name inspect.py to somethingelse.py, importing pandas starts working. enter image description here

I would really like to understand why this is. I assume it has something to do with the module called inspect which (I THINK??) comes by default installed.

Can anyone help me understand this, please?


Solution

  • Looking a np.ma.core.py I see

    import builtins
    import inspect
    import operator
    import warnings
    import textwrap
    import re
    

    These are all base Python modules. Your local inspect.py gets imported instead, which messes with the importing the rest of np.ma.core, and numpy in turn. And pandas depends on numpy.