python-geeks / Automation-scripts

Repo for creating awesome automation scripts to make my panda lazier
MIT License
791 stars 423 forks source link

Installing dependencies from script #929

Open ghost opened 1 year ago

ghost commented 1 year ago

I noticed that a lot of the scripts require the user to install a module or more (obviously!).

Instead of having the user install each module required for each script, why not install these modules FROM the script itself?

I have an example of this over at my ArkEngine repository. The code is here:

import sys
import subprocess as sp

def dependencies(pip = str):
        try:
            sp.call(f'{pip} install pygame', shell = True)
            sp.call(f'{pip} install cryptography', shell = True)
        except:
            print('custom error message')
            sys.exit()

In the code snippet above, the required modules for my project are pygame and cryptography. So in each script, you can add the lines dependencies('pip3') (for macOS users) and/or dependences('pip') (for Windows users). Make sure to modify the dependencies() function to include all the modules you need.

There are many variations, you could also have the code check if the user has the dependencies (modules) installed. If they don't, install it for them. macOS requires pip3, it'll say pip is not a valid command, the same way it does for python.

I think installing the dependent modules from the scripts would improve the UX by removing another step for them.

MalikMlitat commented 1 year ago

hmm, usually you shouldn't change the system without owner's agreement or else you uninstall the modules which you installed after execution