离线装python依赖包

0、首先python脚本是python3编写的,到服务器上运行报缺paramiko module的问题

1、查明服务器的操作系统版本和python版本

[root@localhost ~]# cat /etc/system-release
CentOS Linux release 7.3.1611 (Core)
[root@localhost ~]# pip -V
pip 9.0.3 from /usrb/python3.6/site-packages (python 3.6)
[root@localhost ~]# pip3 -V
pip 9.0.3 from /usrb/python3.6/site-packages (python 3.6)
[root@localhost ~]# python -V
Python 2.7.5
[root@localhost ~]# python3 -V
Python 3.6.8

2、找到对应版本的docker镜像
docker run -v /d:/d -it centos/python-36-centos7 /bin/bash

通过-v 将本地D盘挂载到容器内部的/d目录

3、验证docker容器内的环境

(app-root) cat /etc/system-release
CentOS Linux release 7.7.1908 (Core)
(app-root) pip -V
pip 9.0.1 from /opt/app-root/lib/python3.6/site-packages (python 3.6)

4、通过pip download命令下载依赖库paramiko

(app-root) mkdir /d/paramiko
(app-root) cd /d/paramiko
(app-root) pip download paramiko
...
(app-root) ls
bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.whl      pycparser-2.20-py2.py3-none-any.whl
cffi-1.14.0-cp36-cp36m-manylinux1_x86_64.whl      PyNaCl-1.3.0-cp34-abi3-manylinux1_x86_64.whl
cryptography-2.8-cp34-abi3-manylinux1_x86_64.whl  six-1.14.0-py2.py3-none-any.whl
paramiko-2.7.1-py2.py3-none-any.whl

(app-root) tar zcf paramiko.tgz *

5、离线安装paramiko
在本地D:/paramiko找到paramiko.tgz,上传到服务器,解压

tar zxf paramiko.tgz
pip install *.whl

6、去运行python脚本,搞定!