Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 363
Adam Matan Avatar asked Dec 04 '25 22:12

Adam Matan


1 Answers

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/

like image 114
Bedros Avatar answered Dec 07 '25 13:12

Bedros