8

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

jgritty
  • 11,660
  • 3
  • 38
  • 60
Boaz
  • 4,864
  • 12
  • 50
  • 90

1 Answers1

27
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!
jgritty
  • 11,660
  • 3
  • 38
  • 60
  • what do we need to do if we are using nltk libraries. Do we need to copy the nltk_folder in target machine? – Pyd Oct 25 '17 at 15:57
  • I tried and facing this issue, please check https://stackoverflow.com/questions/46945860/getting-error-when-converting-a-pyscript-to-exe-using-py2exe – Pyd Oct 26 '17 at 04:30