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

3
  • 4
    Did you try to access sys.argv in a py2exe application? What was the problem? Commented Feb 29, 2012 at 10:30
  • Don't forget to actually accept :) Commented Feb 29, 2012 at 10:48
  • I tried, I am facing this issue, please take a look : stackoverflow.com/questions/46945860/… Commented Oct 26, 2017 at 4:29

1 Answer 1

28
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!
Sign up to request clarification or add additional context in comments.

2 Comments

what do we need to do if we are using nltk libraries. Do we need to copy the nltk_folder in target machine?
I tried and facing this issue, please check stackoverflow.com/questions/46945860/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.