diff --git a/faker/utils/loading.py b/faker/utils/loading.py index 8a56b1f6bf..2e6f46d17c 100644 --- a/faker/utils/loading.py +++ b/faker/utils/loading.py @@ -7,8 +7,15 @@ def get_path(module): if getattr(sys, 'frozen', False): # frozen - base_dir = os.path.dirname(sys.executable) - lib_dir = os.path.join(base_dir, "lib") + + if getattr(sys, '_MEIPASS', False): + # PyInstaller + lib_dir = getattr(sys, '_MEIPASS') + else: + # others + base_dir = os.path.dirname(sys.executable) + lib_dir = os.path.join(base_dir, "lib") + module_to_rel_path = os.path.join(*module.__package__.split(".")) path = os.path.join(lib_dir, module_to_rel_path) else: @@ -19,9 +26,14 @@ def get_path(module): def list_module(module): path = get_path(module) - modules = [name for _, name, - is_pkg in pkgutil.iter_modules([path]) if is_pkg] - return modules + + if getattr(sys, '_MEIPASS', False): + # PyInstaller + return [name for name in os.listdir(path) + if os.path.isdir(os.path.join(path, name)) and + "__init__.py" in os.listdir(os.path.join(path, name))] + else: + return [name for _, name, is_pkg in pkgutil.iter_modules([path]) if is_pkg] def find_available_locales(providers):