I have this simple Python script. I want to include some sort of condition that checks for the Python module (in my example below subprocess) before running it. If the module is not present, install the module then run the script. If the module is present, skip the installation of the module and run the script. I am struggling with most of the similar scenarios I am seeing online.
import subprocess
ls_output = subprocess.check_output(['ls'])
print ls_output
subprocessis built in to 2.7 and 3.x. It was added to 2.4. You should not try to install it on anything 2.4 or newer.pip,conda,gitcheckout &setup.py? Also would you use avirtual env?subprocessas an example to simplify my question. The actual module is pycurl. I want the script to run only if pycurl is installed. And if its not installed, then install via pip then execute.