allocer allocer - 1 year ago 97
Python Question

Python django modify help file

I would like to modify -h command in django project. I created a project but when I use my own help command

python my_help
I get an error about not installed modules. And this is ok, because I would like to inform user which modules are needed to install before run a project. So, when I call
python my_help
python -h
I want to show info about additional modules which are needed and general info about project. Now I got only error messsages like (I'm using reportlab in project)

from reportlab.lib.pagesizes import A4, letter
ImportError: No module named 'reportlab'

Is it possible to modify default -h option or do something with my own help command to show basic info instead of an error?

Answer Source

You need to modify your import statements like this:

    from reportlab.lib.pagesizes import A4, letter
except ImportError:
    print 'Missing dependency reportlab'

But this is rather unusual. The usual practice is to create a requirments.txt file which can be passed to pip as follows

pip install -r requirements.txt

Which enables the user to easily satisfy all the requirements in one command. If you catch each ImportError and print out a message for each requirement, you are actually forcing the user to type pip install multiple times.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download