ronaldoussoren / py2app

py2app is a Python setuptools command which will allow you to make standalone Mac OS X application bundles and plugins from Python scripts.
Other
340 stars 36 forks source link

If you have the ruamel.yaml library in your dependency, you will get an error when packing #530

Open v3ucn opened 1 month ago

v3ucn commented 1 month ago

my setup.py:

import sys
sys.setrecursionlimit(5000)

import ruamel.yaml

from setuptools import setup

APP = ['webui.py']
DATA_FILES = []
OPTIONS = {

    'argv_emulation': False,
    'strip': False,  # 不去除debug信息
    'includes': ['gradio','ruamel.yaml'],

}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)
python3 setup.py py2app

it's print:

*** using recipe: detect_dunder_file *** {'packages': {'lightning_fabric', 'pandas', 'lightning', 'importlib_resources', 'torchgen', 'pytz', 'whisper', 'torio', 'multiprocess', 'dill', 'sklearn', 'tqdm', 'pytorch_lightning', 'modelscope', 'aliyunsdkcore', 'torchaudio', 'cffi', 'certifi', 'cosyvoice', 'altair', 'torchmetrics', 'matplotlib', 'numba', 'torch', 'websockets', 'numpy', 'pip', 'yapf_third_party', 'typer', 'dotenv', 'gradio', 'huggingface_hub', 'scipy', 'pydantic', 'librosa', 'jieba', 'ruamel', 'lightning_utilities', 'pyarrow', 'diffusers', 'sympy', 'gradio_client', 'Crypto', 'networkx', 'torchvision'}}

there's "ruamel" in the dict

got this error:

  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/imp.py", line 300, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'ruamel'

the thing is, there isn't a library named "ruamel", it's only "ruamel.yaml", need help guys, many thanks

v3ucn commented 1 month ago

just edit util.py to pass this bug:

def imp_find_module(name, path=None):
    """
    same as imp.find_module, but handles dotted names
    """
    names = name.split(".")
    print(names)

    if names == ['ruamel']:
        return (None, '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ruamel', ('', '', 5))

    if path is not None:
        if isinstance(path, (str, unicode)):
            path = [os.path.realpath(path)]
    for name in names:
        # if name != "ruamel":
        result = imp.find_module(name, path)
        if result[0] is not None:
            result[0].close()
        path = [result[1]]
    print(result)
    return result
jwojcik999 commented 3 weeks ago

Did you try putting the yaml file inside the resources dict?

OPTIONS = {
    'argv_emulation': False,
    'strip': False,  # 不去除debug信息
    'includes': ['gradio'],
    'resources': ['ruamel.yaml'],
}