python打包exe

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/net_matrix/article/details/52548862

1 使用PyInstaller

安装:pip install pyinstaller

将所有文件打包到同一个exe中,使用下面命令:

python "C:\Program Files\Python27\Scripts\pyinstaller-script.py"  -F -w -p .\mylibs  main.py

注意pyinstaller的版本要和python对应,如果python的安装路径存在空格的话,pyinstaller需要使用完整的路径。

参数说明:

-F :Create a one-file bundled executable.

-p:A path to search for imports (like using PYTHONPATH). Multiple paths are allowed, separated by ‘:’, or use this option multiple times


2 使用 py2exe

编写打包脚本mysetup.py,然后执行python mysetup.py

from distutils.core import setup
import py2exe
import sys

sys.argv.append('py2exe')
#引入其他模块
sys.path.insert(0, 'mylibs')

py2exe_options = {
	"includes":["sip"],
	"dll_excludes":["MSVCP90.dll", "numpy-atlas.dll"],
	"compressed":1,
	"optimize":2,
}

setup(
	version='1.0',
	name='main',
	windows=["main.py"],
	zipfile = None,
	options = {'py2exe':py2exe_options}
	)

展开阅读全文

没有更多推荐了,返回首页