Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

py2exe - making exe file from python that uses command line arguments

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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!

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...