1. 到你想要打包的文件夹路径下面输入cmd
2.使用pyinstaller打包项目,首先你要先安装过pyinstaller,pip install pyinstaller,然后在控制台输入打包命令
-F 是只生成一个单个文件(只有一个 exe 文件)
-w 是运行程序时不弹出命令行窗口,只对windows有效
-i 是添加icon图片,后面跟着图标的名字,我这里是nw.ico,然后是你想要打包的文件名字
3.打包结果
这里在文件夹里面出现两个文件夹,一个dist一个build,在dist里面就可以找到单个exe文件
有关打包路径的问题:
我是想要在程序中读取某个文件夹里面的文件,使用了各种方法都不行,最后是这样解决的:
if getattr(sys, 'frozen', False):
current_path = os.path.dirname(os.path.abspath(sys.executable))
elif __file__:
current_path = os.path.dirname(os.path.abspath(__file__))
self.model_mobilenet_v3_large = os.path.join(current_path,"models", "mobilenet_v3_large_state_dict.pkl")
self.model_mobilenet_v3_small = os.path.join(current_path,"models", "mobilenet_v3_small_state_dict.pkl")
self.model_InceptionV3 = os.path.join(current_path,"models", "InceptionV3_state_dict.pkl")
self.model_ResNet152 = os.path.join(current_path,"models", "ResNet152_state_dict.pkl")
以后可以这样解决