I want to create an exe from a python script that uses command line arguments (argv)
From what I've seen py2exe doesn't support command-line-arguments
What can I do?
EDIT: I was using a GUI2Exe tool, so I just missed the Console flag, but the accepted answer is perfectly correct
It is not that you share that Python program with everyone, and they will run this script in some IDLE shell. But you want everyone to run your Python script without the installation of Python. So for this work, you can convert the . py file to .exe file.
To add arguments to Python scripts, you will have to use a built-in module named “argparse”. As the name suggests, it parses command line arguments used while launching a Python script or application. These parsed arguments are also checked by the “argparse” module to ensure that they are of proper “type”.
In PyInstaller it is easy to create one exe, By default both create a bunch of exes & dlls. In py2exe its easier to embed manifest file in exe, useful for run as administrator mode in windows vista and beyond. Pyinstaller is modular and has a feature of hooks to include files in the build that you like.
setup(console=['hello.py'])
I believe the line you want to use looks like this.
I tested this with 2 files:
hello.py
import sys
for arg in sys.argv:
print arg
print "Hello World!"
And setup.py
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
I ran these commands:
python setup.py py2exe
And then in the dist folder, I ran this:
hello.exe foo bar
Result:
hello.exe
foo
bar
Hello World!
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