py2exe 可执行文件不使用 sys.argv[x]
我用 python 编写了一段非常简单的代码,并使用 py2exe 生成了一个 .exe。
我添加了导入以查看导入这些模块是否存在问题。
import sys
import time, os, httplib2
from csv import writer, reader, DictWriter
from BeautifulSoup import BeautifulSoup
def main():
print sys.argv[1]
if __name__ == '__main__':
main()
当我将它作为 .py 文件运行时,效果很好。
C:\Users\User>C:\Python27\Lib\site-packages\py2exe\samples\sysargv\module3.py 只是检查只是检查
但是当我运行生成的可执行文件 py2exe 时它什么也不做 -
C:\Users\User>C:\Python27\Lib\site-packages\py2exe\samples\sysargv\dist\module3.exe JustCheking
这是 setup.py 的代码
from distutils.core import setup
import py2exe
setup(
options = {'py2exe': {'bundle_files': 1}},
windows = [{'script': "module3.py"}],
zipfile = None,
)
我需要在程序中使用 sys.argv (我'正在从用户获取输入,例如输出目录、日志文件路径等')
在使用 py2exe 创建一个可执行文件时如何使用 sys.argv?
另一个问题,如果我在 win7 64 位计算机上安装了 python 2.7 32 位(我已经安装了 常规 win' 2.7.2 来自 python.org 的 msi 文件)并在该计算机上生成了单个可执行文件,我可以在 win7\xp 32 位上使用 .exe 吗?
谢谢
I've written a very simple code in python and generated one .exe with py2exe.
I've added the imports to see if there's a problem with importing those modules.
import sys
import time, os, httplib2
from csv import writer, reader, DictWriter
from BeautifulSoup import BeautifulSoup
def main():
print sys.argv[1]
if __name__ == '__main__':
main()
when I run it as a .py file it works great.
C:\Users\User>C:\Python27\Lib\site-packages\py2exe\samples\sysargv\module3.py
justChecking justChecking
but when I run the executable py2exe had generated it does nothing -
C:\Users\User>C:\Python27\Lib\site-packages\py2exe\samples\sysargv\dist\module3.exe JustCheking
that's the code of the setup.py
from distutils.core import setup
import py2exe
setup(
options = {'py2exe': {'bundle_files': 1}},
windows = [{'script': "module3.py"}],
zipfile = None,
)
I need to use sys.argv in my program (I'm getting input from the user, things like output directory, log file path etc')
how do I use sys.argv when using py2exe to create one executable?
another question, if I have python 2.7 32 bit installed on a win7 64 bit computer (I've installed the regular win' 2.7.2 msi file from python.org) and generated a single executable on that computer, will I be able to use the .exe on win7\xp 32 bit?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是您使用的是 Windows 选项而不是控制台选项。它用于 GUI 应用程序。如果 gui 选项有效,那么它可能会生成一个新终端,一旦程序执行完毕,该终端将立即关闭。
您应该能够在 Windows 7 上使用 32 位 python 编译它,并在任何其他 32 位机器上使用它。
My guess would be that you are using the windows option instead of the console option. That is used for gui apps. If the gui option works, then it would probably spawn a new terminal, which would immediately close once your program is done executing.
You should be able to compile it on windows 7 with 32 bit python and use it on any other 32 bit machine.