Is there a way to change python / pip when import is not performed at runtime , it will try to install the module (with the same name) from pip and then import the module?
I would say that it would be better by default than just throwing an error. If there are any problems after loading the module from pip, then it also gives an error similar to when I notice that I can’t import something, try pip install and then it will come to the exact same error message.
I know that we can use requirements.txt to bind the package, but I speak from the “client” (the person using the script), and not the “provider” (the person providing the script); that is, as a client, I would like to be able to import any script and automatically resolve dependencies.
I understand that this can cause problems, but whenever I see ImportError, I just try to pip install module anyway. Only if the module will not work after installing the software "I will ask additional questions."
I thought of something like this snippet that will be “embedded” in the python process:
def getDirectoryOfInterpreter(p): return "someway to return the directory" try: import somemodule except ImportError: os.system(getDirectoryOfInterpreter('THIS_INTERPRETER_BINARY') + ' pip install ' + "MODULE_NAME") import somemodule
python pip automation
PascalVKooten
source share