从使用命令行参数的python制作exe文件

时间:2021-10-22 23:17:29

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

我想从使用命令行参数的python脚本创建一个exe(argv)从我看到的py2exe不支持命令行参数

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

编辑:我使用的是GUI2Exe工具,所以我只是错过了控制台标志,但接受的答案是完全正确的

1 个解决方案

#1


21  

setup(console=['hello.py'])

I believe the line you want to use looks like this.

我相信你想要使用的那条线看起来像这样。

I tested this with 2 files:

我用2个文件测试了这个:

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:

然后在dist文件夹中,我运行了这个:

hello.exe foo bar

Result:

hello.exe
foo
bar
Hello World!

#1


21  

setup(console=['hello.py'])

I believe the line you want to use looks like this.

我相信你想要使用的那条线看起来像这样。

I tested this with 2 files:

我用2个文件测试了这个:

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:

然后在dist文件夹中,我运行了这个:

hello.exe foo bar

Result:

hello.exe
foo
bar
Hello World!