I have a script that looks like this:
import pip
import sys
def main(argv):
...[does stuff]...
if __name__ == "__main__":
main(sys.argv[1:])
I would like to implement this function i found on stack that imports a package (or install it if nescessary).
def import_or_install(package):
try:
__import__(package)
except ImportError:
pip.main(['install', package])
My vision is that if i run a script on a random computer, if the packaged needed to run said script are not installed, the script does it automatically; Otherwise, import the module.
When I try to run it, I get a NameError stating that the modules I call within main() are not defined.
Link to where I found the function: Check if module exists, if not install it