从使用命令行参数的python制作exe文件 [英] making exe file from python that uses command line arguments

查看:58
本文介绍了从使用命令行参数的python制作exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我能做什么?

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

I was using a GUI2Exe tool, so I just missed the Console flag, but the accepted answer is perfectly correct

推荐答案

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

我相信您要使用的行看起来像这样.

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

我用 2 个文件对此进行了测试:

I tested this with 2 files:

hello.py

import sys

for arg in sys.argv:
    print arg
print "Hello World!"

和 setup.py

from distutils.core import setup
import py2exe

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

我运行了这些命令:

python setup.py py2exe

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

And then in the dist folder, I ran this:

hello.exe foo bar

结果:

hello.exe
foo
bar
Hello World!

这篇关于从使用命令行参数的python制作exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆