python pip将一个包和其依赖包全部下载下来

20 篇文章 0 订阅
pip download -d save_path packages
-d:后面接下载包路径(save_path)
packages:安装包名称
例如本人想下载requests这个包,且保存在demo文件夹里面
pip download -d demo requests

步骤一:

1.1 下面下载过程
bubble@bubble:~$ pip download -d demo requests
Collecting requests
  Downloading https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl (57kB)
    100% |████████████████████████████████| 61kB 69kB/s 
  Saved ./demo/requests-2.22.0-py2.py3-none-any.whl
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests)
  Downloading https://files.pythonhosted.org/packages/e0/da/55f51ea951e1b7c63a579c09dd7db825bb730ec1fe9c0180fc77bfb31448/urllib3-1.25.6-py2.py3-none-any.whl (125kB)
    100% |████████████████████████████████| 133kB 85kB/s 
  Saved ./demo/urllib3-1.25.6-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
  Downloading https://files.pythonhosted.org/packages/18/b0/8146a4f8dd402f60744fa380bc73ca47303cccf8b9190fd16a827281eac2/certifi-2019.9.11-py2.py3-none-any.whl (154kB)
    100% |████████████████████████████████| 163kB 21kB/s 
  Saved ./demo/certifi-2019.9.11-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 9.9kB/s 
  Saved ./demo/chardet-3.0.4-py2.py3-none-any.whl
Collecting idna<2.9,>=2.5 (from requests)
  Downloading https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 25kB/s 
  Saved ./demo/idna-2.8-py2.py3-none-any.whl
Successfully downloaded requests urllib3 certifi chardet idna
1.2下载文件详情
demo
├── certifi-2019.9.11-py2.py3-none-any.whl
├── chardet-3.0.4-py2.py3-none-any.whl
├── idna-2.8-py2.py3-none-any.whl
├── requests-2.22.0-py2.py3-none-any.whl
└── urllib3-1.25.6-py2.py3-none-any.whl

步骤二

创建requirements.txt文档和离线安装刚才下载的包
2.1在demo文件夹下面创建一个requirements.txt,其文件夹(本文下载的是requests离线宝和其依赖包)内容如下:
demo
├── certifi-2019.9.11-py2.py3-none-any.whl
├── chardet-3.0.4-py2.py3-none-any.whl
├── idna-2.8-py2.py3-none-any.whl
├── requests-2.22.0-py2.py3-none-any.whl
├── requirements.txt
└── urllib3-1.25.6-py2.py3-none-any.whl
2.2requirement.txt内容

本文下载的是requests离线宝和其依赖包,根据自己离线下载的包进行调整,规则如下:
requirement.txt里内容按照在终端下载安装包的顺序从低往上写入其中,例如下面是和终端下载顺序是相反的

idna-2.8-py2.py3-none-any.whl
chardet-3.0.4-py2.py3-none-any.whl
certifi-2019.9.11-py2.py3-none-any.whl
urllib3-1.25.6-py2.py3-none-any.whl
requests-2.22.0-py2.py3-none-any.whl
2.3离线安装刚才下载的安装包

终端进入demo文件夹目录路径,输入下面命令:

sudo pip install -r requirements.txt

安装过程如下,每个人情况略有不同:

root@5e9f988c33f5:~/demo# pip install -r requirements.txt
Processing ./idna-2.8-py2.py3-none-any.whl
Processing ./chardet-3.0.4-py2.py3-none-any.whl
Processing ./certifi-2019.9.11-py2.py3-none-any.whl
Processing ./urllib3-1.25.6-py2.py3-none-any.whl
Processing ./requests-2.22.0-py2.py3-none-any.whl
Installing collected packages: idna, chardet, certifi, urllib3, requests
  Found existing installation: idna 2.0
    Not uninstalling idna at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed certifi-2019.9.11 chardet-3.0.4 idna-2.8 requests-2.22.0 urllib3-1.25.6
  • 11
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值