写了一个Python小程序程序(Python3.6, Windows)给公司内部使用,但是需要用户安装Python环境,于是将Python程序打包成exe程序。
一开始使用PyInstaller,但是因为程序里面用到了多进程(multiprocessing),所以打包后双击exe程序运行时,程序会不停的启动进程,但是并没有真正执行进程,网上查了一下,好像PyInstaller会有多进程问题:https://stackoverflow.com/questions/24944558/pyinstaller-built-windows-exe-fails-with-multiprocessing
于是换成用py2exe,但是在打包的过程中会报错:IndexError: tuple index out of range,网上查了一下,发现py2exe好像不支持Python3.6版本:https://stackoverflow.com/questions/41578808/python-indexerror-tuple-index-out-of-range-when-using-py2exe
没有办法,只好再换回PyInstaller,按照网上提到的办法,在 if __name__ == '__main__': 下面加了一行代码:multiprocessing.freeze_support(),再打包,双击exe程序,可以跑起来了。
PyInstaller 具体的使用方法参考:https://blog.youkuaiyun.com/leida_wt/article/details/78698674