I need to find a file contains the module from an egg file.
For example: module_name = "plugins" And the return file within the egg file: "mypackage/plugins.py"
How to do that without importing the module?
I need to find a file contains the module from an egg file.
For example: module_name = "plugins" And the return file within the egg file: "mypackage/plugins.py"
How to do that without importing the module?
Assuming I understand the question..
Just use importlib
and try to import the module.
from importlib import import_module
package_name = "mypackage"
try:
module = import_module("{}.{}".format(package_name, "plugins")
except ImportError:
# The module does not exist
If the module is importable, module
will contain a reference to the initialised module. module.__file__
will also give you the path to the python file.