making exe file from python that uses command line arguments

陌路散爱 提交于 2019-11-26 11:32:47

问题


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


回答1:


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!


来源:https://stackoverflow.com/questions/9497370/making-exe-file-from-python-that-uses-command-line-arguments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!