pip包管理工具 基本使用

# 简介python

  pip是一款包管理工具, 和apt, yum, brew功能相似bootstrap

# 安装windows

wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py

python3 get-pip.py

# 将pip3加入环境变量

vi /etc/profile

export PATH=$PATH:/usr/local/bin

#从新加载环境变量文件

source /etc/profile

# 使用工具

pip3 --help # 可查看帮助信息
pip3 --version 或 pip3 -V # 查看版本信息
which pip3 # 查看安装位置

# 基本操做ui

安装包this

pip3 install requests # 默认安装最早版包
pip3 install requests==1.1.0 # 安装指定版本包

批量安装包阿里云

pip install -r requirements.txt
requirements.txt 文件格式
Werkzeug==0.9.4
psycopg2==2.5.1

卸载包url

pip3 uninstall requests 

更新某个包spa

pip3 install -U requests 

pip3 install --upgrade requests

查看已安装的全部包3d

pip3 list

显示包文件

pip show --files requests

# 配置pip安装源

国内源地址:  

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

# mac
vi .pip/pip.conf # 打开配置文件 # 插入如下内容, 便可切换为豆瓣源 [global] trusted-host=pypi.douban.com index-url=http://pypi.douban.com/simple

# windows在user目录中建立一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容以下
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

# 安装某个包时 指定源

pip3 install requests -i http://pypi.douban.com/simple

# 安装离线包

离线包下载地址 https://www.lfd.uci.edu/~gohlke/pythonlibs/

pip3 install xxxxxxx.whl # 安装

# 安装离线包, 报错: xxx.whl is not a supported wheel on this platform

 解决: 下载系统所支持的离线包便可

# 查看系统支持的安装包

python3 -c "import pip._internal;print(pip._internal.pep425tags.get_supported())"

 

这些就是pip的基本操做, 若有错误, 欢迎交流

相关文章
相关标签/搜索