Using pyinstaller with setuptools package

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Using pyinstaller with setuptools package

Vishesh Mangla
How to write the spec file? I just learned setuptools , made this first package and now I need to build an exe for windows.

I 'm on a win 10, using python=3.8.0 and using PiPy 's latest version of pyinstaller.
```b.spec

def Entrypoint(dist, group, name, **kwargs):
    import pkg_resources

    # get toplevel packages of distribution from metadata
    def get_toplevel(dist):
        distribution = pkg_resources.get_distribution(dist)
        if distribution.has_metadata('top_level.txt'):
            return list(distribution.get_metadata('top_level.txt').split())
        else:
            return []

    kwargs.setdefault('hiddenimports', [])
    packages = []
    for distribution in kwargs['hiddenimports']:
        packages += get_toplevel(distribution)

    kwargs.setdefault('pathex', [])
    # get the entry point
    ep = pkg_resources.get_entry_info(dist, group, name)
    # insert path of the egg at the verify front of the search path
    kwargs['pathex'] = [ep.dist.location] + kwargs['pathex']
    # script name must not be a valid module name to avoid name clashes on import
    script_path = os.path.join(workpath, name + '-script.py')
    print("creating script for entry point", dist, group, name)
    with open(script_path, 'w') as fh:
        print("import", ep.module_name, file=fh)
        print("%s.%s()" % (ep.module_name, '.'.join(ep.attrs)), file=fh)
        for package in packages:
            print("import", package, file=fh)

    return Analysis(
        [script_path] + kwargs.get('scripts', []),
        **kwargs
    )

Entrypoint('mailerkivy', 'gui_scripts', 'mailer.main')
```

```setup.py

import setuptools


setuptools.setup(
    name="mailerkivy",
    version="0.1.1",
  
    python_requires='>=3.7',
    packages=setuptools.find_packages("src"),
    package_dir={"""src"},
    entry_points={
        "gui_scripts": [
            "mailer = mailer.main:main",
        ],
    },
        setup_requires="setuptools",
    install_requires=[
        "kivy>=2.0.0",
        "beautifulsoup4>=4.9.3",
        "docxtpl>=0.11.3",
        "pywin32>=300",
        "plyer>=2.0.0"
        
    ],
   extras_require={
        "build_for_windows":  ["pyinstaller>=4.2""pyinstaller"],
    }
)

```


```traceback
$ pyinstaller --clean --uac-admin b.spec
175 INFO: PyInstaller: 4.2
175 INFO: Python: 3.8.0
176 INFO: Platform: Windows-10-10.0.19041-SP0
188 INFO: UPX is not available.
189 INFO: Removing temporary files and cleaning cache in C:\Users\Dell\AppData\Roaming\pyinstaller
Traceback (most recent call last):
  File "c:\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python38\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "c:\python38\lib\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\python38\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\python38\lib\site-packages\PyInstaller\building\build_main.py", line 725, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\python38\lib\site-packages\PyInstaller\building\build_main.py", line 672, in build
    exec(code, spec_namespace)
  File "b.spec", line 36, in <module>
    Entrypoint('mailerkivy', 'gui_scripts', 'mailer.main')
  File "b.spec", line 19, in Entrypoint
    ep = pkg_resources.get_entry_info(dist, group, name)
  File "c:\python38\lib\site-packages\pkg_resources\__init__.py", line 499, in get_entry_info
    return get_distribution(dist).get_entry_info(group, name)
  File "c:\python38\lib\site-packages\pkg_resources\__init__.py", line 481, in get_distribution
    dist = get_provider(dist)
  File "c:\python38\lib\site-packages\pkg_resources\__init__.py", line 357, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "c:\python38\lib\site-packages\pkg_resources\__init__.py", line 900, in require
    needed = self.resolve(parse_requirements(requirements))
  File "c:\python38\lib\site-packages\pkg_resources\__init__.py", line 786, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'mailerkivy' distribution was not found and is required by the application
```


--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/1247321c-99bd-42d7-b833-215103f47a7dn%40googlegroups.com.