pip包管理工具及打包编译python脚本

一、pip常用命令

pip install package_name==version   # 安装特定版本的包
pip uninstall package_name          # 卸载包
pip index versions package_name     # 查看可用的包版本
pip show package_name               # 查看软件包信息

二、生成requirements.txt依赖包文件方法
1、使用pip freeze命令生成

[root@localhost project]# pip freeze > requirements.txt

2、使用pipreqs命令生成
#安装pipreqs命令

[root@localhost project]# pip install pipreqs

#进入项目执行pipreqs命令

[root@localhost project]# pipreqs ./

三、使用requirements.txt文件安装python包,并修改默认安装源

# --trusted-host禁用证书验证,pip会优先从主索引URL(-i)获取包。如果在主索引找不到,才会去额外的索引URL(--extra-index-url)逐个查找
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple/ --extra-index-url https://pypi.org/simple --trusted-host mirrors.aliyun.com
# 设置全局默认源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 查看当前配置
pip config list
# 重置为官方源
pip config unset global.index-url

四、使用pyinstaller打包编译

pip install pyinstaller   # 安装pyinstaller工具
pyinstaller -F deploy.py --add-data 'config.yaml:.'    # 打包编译
# 注意:
#   1、打包之前请安装requirements.txt文件里的所有依赖包
#   2、打包添加配置文件时,在windows上使用--add-data 'config.yaml;.',在Linux上使用--add-data 'config.yaml:.'
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple py2exe   # 安装py2exe打包编译工具

五、常用常用国内镜像源地址

# 阿里云
https://mirrors.aliyun.com/pypi/simple/
# 清华大学
https://pypi.tuna.tsinghua.edu.cn/simple
# 中国科学技术大学
https://pypi.mirrors.ustc.edu.cn/simple/
# 豆瓣
https://pypi.doubanio.com/simple/

参考链接
       https://www.cnblogs.com/mywolrd/p/4756005.html
       https://www.cnblogs.com/caijunchao/p/12845620.html
       https://www.cnblogs.com/gopythoner/p/6337543.html
       https://github.com/pex-tool/pex      # 使用pex打包
       https://www.toutiao.com/article/7565350759350305286/     # 使用py2exe库打包
       https://developer.aliyun.com/article/1489755         # pip包管理工具
       https://www.cnblogs.com/treasury-manager/p/13952394.html      # python环境设置及包管理
       https://www.toutiao.com/article/7583894246978060852/              # 使用pip-tools工具实现版本锁定

posted @ 2021-05-20 09:51  風£飛  阅读(184)  评论(0)    收藏  举报