Search code examples
pythonmacospython-modulepython-import

Python 2.6.1: Checking if imports exist


I have written a utility script for some of my colleagues' Mac OSX with Python 2.6.1. Since they don't have all the required modules installed, I have a try-except import clause:

try:
    import argparse
except ImportError:
    print "argparse module missing: Please run 'sudo easy_install argparse'"
    sys.exit(1)

I'm pretty sure there are more elegant ways to handle this. Any ideas?


Solution

  • Your best shot is to freeze your python code with all modules needed and distribute it as binary; it worked for me with Windows and Linux, however on Linux, make sure you have a compatible glibc version

    There are some freeze tools for Mac OS X, but I have not used them. I only used Windows and Linux tools.

    check out this link for more info

    http://hackerboss.com/how-to-distribute-commercial-python-applications/