前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >​python-pip 包管理器使用

​python-pip 包管理器使用

原创
作者头像
saosir
修改2021-01-21 16:41:02
8200
修改2021-01-21 16:41:02
举报

pip 安装使用

安装或者更新

代码语言:txt
复制
curl https://bootstrap.pypa.io/get-pip.py | python

如果已经安装直接运行命令更新 pip

代码语言:txt
复制
pip install --upgrade pip

使用国内源加速

手动指定源

代码语言:txt
复制
pip install  -i http://pypi.douban.com/simple web.py

pipy 国内镜像可以考虑下面几个:

代码语言:txt
复制
http://mirrors.aliyun.com/pypi/simple
http://pypi.douban.com/  豆瓣
http://pypi.hustunique.com/  华中理工大学
http://pypi.sdutlinux.org/  山东理工大学
http://pypi.mirrors.ustc.edu.cn/  中国科学技术大学

要配制默认源,需要创建或修改配置文件(linux 的文件在~/.pip/pip.conf,windows 在 %HOMEPATH%\pip\pip.ini):

代码语言:txt
复制
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

安装 python 包

通过包名在线安装

代码语言:txt
复制
$ pip install SomePackage

离线包安装

代码语言:txt
复制
$ pip install SomePackage-1.0-py2.py3-none-any.whl
$ pip install relative_path_to_seaborn.tar.gz    
$ pip install absolute_path_to_seaborn.tar.gz    
$ pip install file:///absolute_path_to_seaborn.tar.gz  

通过 requirements.txt 文件批量安装

代码语言:txt
复制
$ pip install -r requirements-dev.txt

requirements.txt 文件格式说明:

代码语言:txt
复制
[[--option]...]
<requirement specifier> [; markers] [[--option]...]
<archive url/path>
[-e] <local project path>
[-e] <vcs project url>
-r <requirements.txt>

参考requirements.txt文件格式

如果在requirements.txt中安装的某个包需要指定url,可以这样写:

代码语言:txt
复制
-i https://xxxx.com/pypi/xxx/simple
tornado
requests

这样在-i之后的包都使用url=https://xxxx.com/pypi/xxx/simple进行

git 仓库地址安装

代码语言:txt
复制
pip install git+git://github.com/miso-belica/sumy.git
pip install git+ssh://git@github.com/goerz/mgplottools.git@master#egg=mgplottools
pip install git+https://github.com/goerz/mgplottools.git@master#egg=mgplottools
pip install git+git://github.com/goerz/mgplottools.git@master#egg=mgplottool

更新 python 包

显示需要更新的包:

代码语言:txt
复制
$ pip list --outdated
  SomePackage (Current: 1.0 Latest: 2.0)

安装更新:

代码语言:txt
复制
$ pip install --upgrade SomePackage
$ pip install --upgrade SomePackage==version

移除软件包

卸载

代码语言:txt
复制
$ pip uninstall SomePackage
  Uninstalling SomePackage:
    /my/env/lib/pythonx.x/site-packages/somepackage
  Proceed (y/n)? y
  Successfully uninstalled SomePackage

安装异常

pip 出现 IndexError:list index out of range

代码语言:txt
复制
pip install --no-use-wheel --upgrade distribute

离线下载 wheelhouse 包

代码语言:txt
复制
pip install --download wheelhouse -r requirements.txt --trusted-host mirror-sng.oa.com

使用 wheelhouse 安装的时候运行下面命令行

代码语言:txt
复制
pip install -r requirements.txt --no-index --find-links file://`readlink -m ./wheelhouse`

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • pip 安装使用
  • 使用国内源加速
  • 安装 python 包
    • 通过包名在线安装
      • 离线包安装
        • 通过 requirements.txt 文件批量安装
          • git 仓库地址安装
          • 更新 python 包
          • 移除软件包
          • 安装异常
            • pip 出现 IndexError:list index out of range
            • 离线下载 wheelhouse 包
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档