This answer might help you https://stackoverflow.com/a/9271617/4498470
The modules that have set __file__ = None
are probably modules written in C. They are statically linked. Or perhaps the import system has loaded in the module from a database and so there is no 'file' to point to.
I'd say if there's no __file__
attribute set, unless it's a bug, it probably because that attribute is meaningless for a particular module.
Python's import system is pretty complicated. You can read some about the attributes like __file__
here https://docs.python.org/3.8/reference/import.html?highlight=__file__#import-related-module-attributes.
So, the answer to "Is there any other option to get the same data instead using file so I won't get a None" is probably No. (At least for C Python).