一般来说
在
安装 Pyinstaller
首先pip install pyinstaller
- 注意
:
如果你的 需要修改对应目录下的某个文件的注释, 但我这里不写出来。 因为如果你还把, 就算这个问题能够解决, 以后还会有其他的问题, 。
趁早把安装路径改了吧。
打包
直接将命令行切换到写好的运行文件目录下pyinstaller -F 文件名
会帮你处理好依赖关系和文件-F
如果你觉得默认图标太丑-i 图标文件路径
来增加图标
黑框这种东西-w
更多的选项可以查看 Pyinstaller
打包多进程
当你尝试直接打包一个使用了
pyinstaller
if __name__ == "__main__": multiprocessing.freeze_support()
当你的
import os import sys # Module multiprocessing is organized differently in Python 3.4+ try: # Python 3.4+ if sys.platform.startswith('win'): import multiprocessing.popen_spawn_win32 as forking else: import multiprocessing.popen_fork as forking except ImportError: import multiprocessing.forking as forking if sys.platform.startswith('win'): # First define a modified version of Popen. class _Popen(forking.Popen): def __init__(self, *args, **kw): if hasattr(sys, 'frozen'): # We have to set original _MEIPASS2 value from sys._MEIPASS # to get --onefile mode working. os.putenv('_MEIPASS2', sys._MEIPASS) try: super(_Popen, self).__init__(*args, **kw) finally: if hasattr(sys, 'frozen'): # On some platforms (e.g. AIX) 'os.unsetenv()' is not # available. In those cases we cannot delete the variable # but only set it to the empty string. The bootloader # can handle this case. if hasattr(os, 'unsetenv'): os.unsetenv('_MEIPASS2') else: os.putenv('_MEIPASS2', '') # Second override 'Popen' class with our modified version. forking.Popen = _Popen
当然
打包额外文件
当需要打包的时候把一些其他文件复制到--add-data="文件路径;
例如复制根目录下的snake.ico
--add-data="snake.ico;."
:
;