pyinstaller 用来将python 程序打包成一个可执行程序.
之所以需要打包,主要是为了方便给别人使用. 因为不可能每个人电脑都装有python,而且python版本也可能不一样. 所以打包成一个可执行文件可以更方便使用.
In [ ]:
# - *- encoding: utf-8 -*-
import os
import subprocess
import sys
cur_dir = os.getcwd()
pyinstaller_exe = os.path.join(os.path.dirname(sys.executable), 'pyinstaller.exe')
subprocess.check_call("{pyinstaller} -F --icon={icon} --clean {script} --distpath {dist}".format(
pyinstaller=pyinstaller_exe,
icon=os.path.join(cur_dir, "ico.ico"),
script=os.path.join(cur_dir, "console_demo.py"),
dist=cur_dir
), shell=True, cwd=cur_dir)
In [ ]:
# - *- encoding: utf-8 -*-
import os
import subprocess
import sys
cur_dir = os.getcwd()
pyinstaller_exe = os.path.join(os.path.dirname(sys.executable), 'pyinstaller.exe')
subprocess.check_call("{pyinstaller} -w -F --icon={icon} --clean {script} --distpath {dist}".format(
pyinstaller=pyinstaller_exe,
icon=os.path.join(cur_dir, "ico.ico"),
script=os.path.join(cur_dir, "gui_demo.py"),
dist=cur_dir
), shell=True, cwd=cur_dir)