Python程序的封装
1.安装Anaconda:
直接安装,在E盘
2.启动Anaconda:
(1)创建虚拟程序:
conda create -n 虚拟环境名字 python==3.6 //#创建虚拟环境 //一定要基于自己的python版本 conda activate 虚拟环境名字 //#激活虚拟环境 conda deactivate //#退出虚拟环境
(2)激活虚拟环境
conda activate 虚拟环境名字 //#激活虚拟环境 //在创建过程中需要回复(y/n),Yes,再激活虚拟环境 //conda安装的虚拟环境,会把虚拟环境的目录生成在anaconda安装目录下的env目录下。 //当然我们也可以在刚刚的窗口,使用命令conda info --envs,来查看conda环境下所有的虚拟环境
(3)退出虚拟环境
conda deactivate //#退出虚拟环境 //如果不销毁,可以再下一次时直接用 active进入上一次的环境
(4)删除虚拟环境
conda remove -n aotu--all
3.安装所需的库
(1)安装必须的库:pyinstaller、pandas、docx
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas pip install -i https://pypi.tuna.tsinghua.edu.cn/simple python-docx //注:docx不能直接安装,要用python-docx pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller
(2)安装自己所需要的库(自己的代码中所含有的库)
pip install requests -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com pip install loguru -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com pip install pandas -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com
(3)查看自己安装的库
conda list
4.Pyinstaller打包
Pyinstaller -F py_word.py 打包exe Pyinstaller -F -w py_word.py 不带控制台的打包 //不带控制台就是就是不能有输入函数,无法进行输入,只有输出 Pyinstaller -F -w -i chengzi.ico py_word.py 打包指定exe图标打包 //这个图片必须是ico的格式,文件必须是py的格式 //图片转换为ico格式:https://app.xunjiepdf.com/img2icon/ exe文件被储存在list文件当中