If you want use import all with pyinstaller, you'll need the following extra processing.
- define
get_all_pyfile that support .pyc
util/get_all_pyfile
import glob import re from os.path import join, basename, isfile from typing import AnyStr def get_all_pyfile(pathname: AnyStr): modules = glob.glob(join(pathname, "*.py*")) return [ re.sub(r"\.pyc?", "", basename(f)) for f in modules if isfile(f) and not re.search(r"__init__.pyc?$", f) ]
- use
get_all_pyfile in __init__.py
entity/__init__.py
from os.path import dirname from util.get_all_pyfile import get_all_pyfile __all__ = get_all_pyfile(dirname(__file__))
- add
hidden imports in pyinstaller spec file
/main.spec
# -*- mode: python ; coding: utf-8 -*- import os import sys from PyInstaller.building.api import PYZ, EXE, COLLECT from PyInstaller.building.build_main import Analysis from PyInstaller.utils.hooks import collect_submodules venv_path = os.path.dirname(os.path.realpath("__file__")) sys.path.append(os.path.join(venv_path, "../")) hidden_imports_entity = collect_submodules("entity") print(hidden_imports_entity) a = Analysis( [".\\main.py"], pathex=[], binaries=[], datas=[], hiddenimports=hidden_imports_entity, hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[], noarchive=True, ) ...