1、cmd下输入:pip install py2exe

2、在你需要转换的python文件目录中新建setup.py文件,并写上如下代码:
from distutils.core import setupimport py2exesetup(windows=['createfile.py']
(如果将windows改为console,生成的文件就会有cmd框,“createfile.py”为你的文件名)


3、cmd下定位到当前目录
输入:python setup.py py2exe
就可以了

4、还有一种就是再当前目录下新建txt文件并写上:python setup.py py2exe

5、把txt文件后缀改为bat。
双击运行就可以了

6、"dist"文件夹为生成的文件,"_pycache_"为中间文件不用理会。
exe文件再dist文件夹中,dist 文件夹中其他文件为库文件

