Why does module.__file__ return None?

Viewed 1283

I've added a local directory to my system path. When I import it, it's fine but when I do

import local_repo 
print(local_repo.__file__) 

it returns None.

How do I get it to return the path...

P.S. When I try this with other modules works fine - returns the path - for example

import pathlib 
print(pathlib.__file__)

>>>> "C:\Python38\lib\pathlib.py"
2 Answers

__init__.py file should solve it.

Possibly not an answer to your specific situation, but I had issues with code in a parent package. The code was preventing the child module from initializing properly and the errors were cryptic and pointed at other modules. If you run into this issue, you may want to check other parent and imported modules.

Related