In the python script, ArgumentParser will displays the parser’s help message by default if -h or --help is supplied at the command line.
(base) D:\Study\Github\BVPA-GUI>python src\plot_auto.py -h
usage: plot_auto.py [-h] [--legend] [--figname FIGNAME]
optional arguments:
-h, --help show this help message and exit
--legend Show legend on plot.
--figname FIGNAME Specify the window title.
However it will not work if I compile the python script into exe application by pyinstaller.
D:\Study\Github\BVPA-GUI>.\bin\plotting\plot_auto.exe -h
What is the reason for this and what can I do about this?
Have you ever used sys.argv with pyinstaller?
You can check that it works well.
See argparse python official document, especially parse_args parts.
It makes a parsed arguments with the given console arguments or the given string list on function interface, parse_args(['arg1', 'arg2', ... ]).
Let's apply to your application. Very simple.
import sys, argparse
parser = argparse.ArgumentParser()
# add arguments settings ------------
.
.
.
#------------------------------------
if __name__ == "__main__":
args = parser.parse_args(sys.argv[1:])
# Your program code
I also tried same work with you.
It worked well to me.
I hope it is usefull to you too.
#Note:
In the official document said that parse_args function get default arguments from sys.argv but it doesn't seems to work with pyinstaller.
The above is just manually add such progress.
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