1.安装pyinstaller
pip install pyinstaller
2.使用anaconda 创建虚拟环境
conda create -n hefa python=3.6
3.激活虚拟环境,安装你需要的包
conda activate hefa
pip install keras
4.打包exex
pyinstaller -F server.py -p G:\Anaconda3\envs\hefa\Lib\site-packages --additional-hooks-dir=hooks
其中-p 就是你虚拟环境下的安装的包的路径 --additional 是因为我使用了tensorlfow报错,参考文章加上去的
5.tips
1.自己写的代码中尽量使用什么就from什么,加上一个import keras exe就会多加300M。所以尽量使用from而不是import。
2.打包好的exe找不到原来的资源的,必须复制到当前目录下才可以使用,比如配置文件和h5权重。
6.报错解决:
utf-8,命令运行前,运行下面的
chcp 65001
7.RecursionError: maximum recursion depth exceeded while calling a Python object
在spec文件中插入
import sys
sys.setrecursionlimit(1000000)
然后运行
pyInstaller xx.spec
报错!!!
Error: geos_c.dll not found, required by hook-shapely.py.
Please check your installation or provide a pull request to PyInstaller to update hook-shapely.py
去下载geos_c.dll https://www.dll-files.com/geos_c.dll.html
放在C:\Windows\System32 下