Search code examples
pythondependency-management.app

How to make a Python exe file automatically install dependancies?


I have made an application using python using some libraries installed as needed on the go. Now I want to make it usable for person who doesn't know how to install dependencies and which ones are needed. What to do to transform it into an easy to use application and probably make it able to run on Mac too??

Please suggest some resources that might help me know more.


Solution

  • When making the executable you should declare the modules with it, you can then just copy the library files to the same location as the programme.

    I use cx_freeze when making exe's and an example setup.py files looks like this:

    from cx_Freeze import setup, Executable
    
    base = None    
    
    executables = [Executable("projectname.py", base=base)]
    
    packages = ["idna","os","shutil","csv","time","whatever else you like"]
    options = {
        'build_exe': {    
            'packages':packages,
        },    
    }
    
    setup(
        name = "Some Project",
        options = options,
        version = "1.2.3",
        description = 'Generic Description',
        executables = executables
    )
    

    Packages are where the modules are declared.

    If you have a quick search online it'll give you complete guides for it, all you'd need to do then is copy the lot across to your friend's computer.

    Hope this helps!