封装模块:
1、先准备好要封装的 .py 文件demo.dy
内容如下:
def add(a, b):
c = a + b
return c
2、设置文件名例如路径:例如(D:\mymodule\demo.py)(1)文件夹名字(mymodule)
(2).py 文件的名字(demo.py)
(3).py 文件里的类名或者函数名(add)
3、将需要封装的模块打包成 .exe 文件放置到 python 安装包的 D:/python/Lib/site-packages目录下
打包步骤:---------
(1)下载 pyinstallerpip install pyinstaller # 下载
pip install --upgrade pyinstaller # 更新
(2)打包 .py 文件成 .exe 程序第一步:打开终端(win + R),C:\Users\\username>
第二步:切换路径到需要打包的 .py 文件目录下,
C:\Users\\username>d: # 切换目录到 D 盘
D:\>cd D:\mymodule # 切换目录到需要打包的 .py 文件目录下
第三步:生成 .exe 文件
格式(pyinstaller -F 需要打包的 .py 文件)
D:\mymodule>pyinstaller -F demo.py # 回车,到这里已完成打包
第四步:将打包好的模块(mymodule文件夹)【复制到】 python 安装包的<