1.安裝對應python版本的py2exe
2.假設你要生成test.py腳本的exe文件
新建一個setup.py,在里面輸入如下代碼
1 #!/usr/bin/python 2 from distutils.core import setup 3 import py2exe 4 import os,sys 5 6 CurrentPath = os.path.dirname(sys.argv[0]) 7 setup(console=[str(CurrentPath)+'test.py'])
保存退出
3.打開cmd,輸入命令
python setup.py py2exe
成功后在dist文件夾中就會生成exe文件了。