I'm writing a quick shell script to make it easier for some of our developers to run Fabric. (I'm also new to Python.) Part of installing Fabric is installing pip, and part of installing pip is installing setuptools.
Is there any easy way to detect if setuptools is already installed? I'd like to make it possible to run the script multiple times, and it skip anything it's already done. As it stands now, if you run ez_setup.py twice in a row, you'll get a failure the second time.
One idea I had was to look for the easy_install scripts under the /Scripts folder. I can guess at the Python root using sys.executable, and then swap off the executable name itself. But I'm looking for something a little more elegant (and perhaps cross-OS friendly). Any suggestions?
Try with this command.
$ pip list
It returns the versions of both pip
and setuptools
. Otherwise try with
$ pip install pil
If this also doesn't work, then try with
$ which easy_install
This isn't great but it'll work.
A simple python script can do the check
import sys
try:
import setuptools
except ImportError:
sys.exit(1)
else:
sys.exit(0)
OR
try:
import setuptools
except ImportError:
print("Not installed.")
else:
print("Installed.")
Then just check it's exit code in the calling script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With