pip笔记

pip介绍

pip的全称:package installer for python,也就是Python包管理工具。

配置镜像源

镜像列表

  1. 阿里云 http://mirrors.aliyun.com/pypi/simple/
  2. 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
  3. 豆瓣 http://pypi.douban.com/simple/
  4. 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
  5. 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

临时使用

复制代码
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy

永久使用

  1. windows下在user目录中创建一个pip文件夹(一般都是不存在的 ,需要自己创建), 如C:\Users\jarvis\pip,在pip文件夹中新建文件pip.ini,内容如下:

    [global]
    timeout = 40
    index-url = https://mirrors.aliyun.com/pypi/simple/
    extra-index-url = https://pypi.mirrors.ustc.edu.cn/simple/
    http://pypi.douban.com/simple/
    https://pypi.tuna.tsinghua.edu.cn/simple/
    http://pypi.mirrors.ustc.edu.cn/simple/
    [install]
    trusted-host = mirrors.aliyun.com
    pypi.mirrors.ustc.edu.cn
    pypi.douban.com
    pypi.tuna.tsinghua.edu.cn
    pypi.mirrors.ustc.edu.cn

  2. 查看更改后的镜像源:pip config list

常用方法

查看包

bash 复制代码
# 查看版本号
pip --version 	

# 查看所有已安装包
pip list  

# 查看包详情
pip show -f beautifulsoup4  

# 验证已经安装的包是否有兼容依赖问题
pip check beautifulsoup4  

更新pip

bash 复制代码
# 方法1
pip install --upgrade pip  

# 方法2
python -m pip install --upgrade pip  

安装卸载

bash 复制代码
# 安装包,默认安装最新版本
pip install beautifulsoup4  

# 临时使用指定源安装
pip install beautifulsoup4 -i https://pypi.tuna.tsinghua.edu.cn/simple 

# 安装指定版本包
pip install mataplotlib==3.4.1 	

# 批量安装包
pip install -r d:\\requirments.txt 	

# 离线安装 *.whl 包 
pip install PyQt5-5.10.1-5.10.1-cp35.cp36.cp37.cp38-none-win_amd64.whl  

# 卸载包
pip uninstall beautifulsoup4  

# 重新安装pip, -U表示自动安装最新版
easy_install -U pip   

升级包

bash 复制代码
# 查看需要升级的包 完整写法:pip list --outdated 
pip list -o 

# 升级包
pip install --upgrade beautifulsoup4  

其他

复制代码
# 下载django包到本地桌面 
pip download django -d C:\Users\jarvis\Desktop  

# 设置默认镜像源
pip config setglobal.index-url https://pypi.tuna.tsinghua.edu.cn/simple  

环境打包及安装

打包方法1:freeze 打包

pip freeze 会将当前PC环境下所有的安装包都进行生成,再进行安装的时候会全部安装很多没有的包.耗时耗力其实是不可取的。

bash 复制代码
# pip 自带方法 不推荐 可能会丢失依赖包的版本号
pip freeze > requirements.txt
# 或者
pip list --format=freeze> requirements.txt

打包方法2:pipreqs 打包

使用pipreqs,这个工具的好处是可以通过对项目目录的扫描,发现使用了哪些库,生成依赖清单。

bash 复制代码
# 安装 pipreqs
pip install pipreqs
# 生成
pipreqs . --encoding=utf8 --force

安装所有包

bash 复制代码
# 安装
pip install -r requirements.txt

卸载所有包

使用命令,按照导出的库的列表,卸载库文件

bash 复制代码
pip uninstall -r requirements.txt -y

至此,所有的第三方库就已经卸载干净,运行pip list会得到如下结果:

bash 复制代码
Package    Version
---------- -------
pip        24.0
setuptools 40.8.0
相关推荐
羊群智妍1 天前
2026 AI搜索流量密码:免费GEO监测工具,优化效果看得见
笔记·百度·微信·facebook·新浪微博
山岚的运维笔记1 天前
SQL Server笔记 -- 第18章:Views
数据库·笔记·sql·microsoft·sqlserver
lpruoyu1 天前
【Android第一行代码学习笔记】Android架构_四大组件_权限_持久化_通知_异步_服务
android·笔记·学习
wdfk_prog1 天前
[Linux]学习笔记系列 -- [drivers][mmc][mmc_sdio]
linux·笔记·学习
果果燕1 天前
今日学习笔记:双向链表、循环链表、栈
笔记·学习·链表
觉醒大王1 天前
AI写的青基中了
人工智能·笔记·深度学习·学习·职场和发展·学习方法
明月醉窗台1 天前
qt使用笔记六之 Qt Creator、Qt Widgets、Qt Quick 详细解析
开发语言·笔记·qt
Hello_Embed2 天前
libmodbus 移植 STM32(USB 串口后端篇)
笔记·stm32·单片机·嵌入式·freertos·libmodbus
张祥6422889042 天前
RTKLIB源码和理论结合分析笔记三
笔记
日更嵌入式的打工仔2 天前
0欧电阻作用
笔记