py2exe executable doesn't use sys.argv[x]
I've written a very simple code in python and generated one .exe with py2exe.
I've added th开发者_开发技巧e 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
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.
精彩评论