离线方式快速安装python模块以及相关依赖模块

一般公司的服务器都是和外网隔离的,这个如果没有内部pip源的话,想要安装python的模块就需要去python官网一个一个下载依赖模块的包,然后逐个安装,这样做非常耗时间。

我们今天用的办法就是现在我们能够连接公网的linux机器上面先使用pip命令安装好我们需要的python模块。然后再将需要的模块一键下载并拷贝到服务器上一键安装。步骤如下:

前提条件:

  如果服务器是linux的,我们就需要一个能连公网的linux,不能使用windows是因为,有很多模块linux和windows两个平台不是共用的,在安装的时候会报错。

步骤:

1、在能连接公网的linux机器上使用pip命令安装好需要的模块。(pip安装的好处是:会自动帮你把依赖模块安装好)

pip3 install -i https://mirrors.aliyun.com/pypi/simple/ sh
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ docker-py
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ fabric
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ paramiko
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ psutil
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ PyMySQL
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ redis
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ requests
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ selenium
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ SQLAlchemy
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ tornado
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ xlrd
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ xlwt
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ xmltodict
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ celery
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ celery-flower

2、然后在能连接公网的机器上执行pip freeze>python3_module.txt,这样就可以将你之前安装的模块列表导出来

3、列表导出来以后就需要根据这个列表去把模块的代码文件从公网下载下来,执行mkdir python3_package && pip3 download -r python3_modules.txt -d python3_packages/ -i https://mirrors.aliyun.com/pypi/simple/  ,这里我们使用了阿里的源,这样下载的速度会快很多

4、将下载完的文件夹打包,mv python3_modules.txt python3_packages/ && tar -czf python3_packages.tar.gz python3_packages,然后将打包完的文件上传到服务器上解压,tar -xzf python3_packages.tar.gz。

5、在服务器上安装我们的模块(前提需要安装和能连接公网的linux机器版本相同的python),cd python3_packages && /opt/samp/venv/python3/bin/pip3 install --no-index --find-links=file:. -r python3_modules.txt,等待安装完成即可,这样可以避免让人奔溃的依赖模块一个一个安装问题。

[root@itsasitapp213 python3_packages]# /opt/samp/venv/python3/bin/pip3 install --no-index --find-links=file:. -r python3_modules.txt 
Looking in links: file:.
Collecting amqp==2.4.2 (from -r python3_modules.txt (line 1))
Collecting asn1crypto==0.24.0 (from -r python3_modules.txt (line 2))
Collecting Babel==2.6.0 (from -r python3_modules.txt (line 3))
Collecting bcrypt==3.1.6 (from -r python3_modules.txt (line 4))
Collecting billiard==3.5.0.5 (from -r python3_modules.txt (line 5))
Collecting celery==4.2.1 (from -r python3_modules.txt (line 6))
Collecting celery-flower==1.0.1 (from -r python3_modules.txt (line 7))
Collecting certifi==2018.11.29 (from -r python3_modules.txt (line 8))
Collecting cffi==1.12.2 (from -r python3_modules.txt (line 9))
Collecting chardet==3.0.4 (from -r python3_modules.txt (line 10))
Collecting cryptography==2.6.1 (from -r python3_modules.txt (line 11))
Collecting docker-py==1.10.6 (from -r python3_modules.txt (line 12))
Collecting docker-pycreds==0.4.0 (from -r python3_modules.txt (line 13))
Collecting fabric==2.4.0 (from -r python3_modules.txt (line 14))
Collecting idna==2.8 (from -r python3_modules.txt (line 15))
Collecting invoke==1.2.0 (from -r python3_modules.txt (line 16))
Collecting kombu==4.4.0 (from -r python3_modules.txt (line 17))
Collecting paramiko==2.4.2 (from -r python3_modules.txt (line 18))
Collecting psutil==5.6.0 (from -r python3_modules.txt (line 19))
Collecting pyasn1==0.4.5 (from -r python3_modules.txt (line 20))
Collecting pycparser==2.19 (from -r python3_modules.txt (line 21))
Collecting PyMySQL==0.9.3 (from -r python3_modules.txt (line 22))
Collecting PyNaCl==1.3.0 (from -r python3_modules.txt (line 23))
Collecting pytz==2018.9 (from -r python3_modules.txt (line 24))
Collecting redis==3.2.0 (from -r python3_modules.txt (line 25))
Collecting requests==2.21.0 (from -r python3_modules.txt (line 26))
Collecting selenium==3.141.0 (from -r python3_modules.txt (line 27))
Collecting sh==1.12.14 (from -r python3_modules.txt (line 28))
Collecting six==1.12.0 (from -r python3_modules.txt (line 29))
Collecting SQLAlchemy==1.3.0 (from -r python3_modules.txt (line 30))
Collecting tornado==6.0.1 (from -r python3_modules.txt (line 31))
Collecting urllib3==1.24.1 (from -r python3_modules.txt (line 32))
Collecting vine==1.2.0 (from -r python3_modules.txt (line 33))
Collecting websocket-client==0.55.0 (from -r python3_modules.txt (line 34))
Collecting xlrd==1.2.0 (from -r python3_modules.txt (line 35))
Collecting xlwt==1.3.0 (from -r python3_modules.txt (line 36))
Collecting xmltodict==0.12.0 (from -r python3_modules.txt (line 37))
Installing collected packages: vine, amqp, asn1crypto, pytz, Babel, six, pycparser, cffi, bcrypt, billiard, kombu, celery, tornado, celery-flower, certifi, chardet, cryptography, websocket-client, docker-pycreds, urllib3, idna, requests, docker-py, invoke, pyasn1, PyNaCl, paramiko, fabric, psutil, PyMySQL, redis, selenium, sh, SQLAlchemy, xlrd, xlwt, xmltodict
  Running setup.py install for pycparser ... done
  Running setup.py install for billiard ... done
  Running setup.py install for tornado ... done
  Running setup.py install for celery-flower ... done
  Running setup.py install for psutil ... done
  Running setup.py install for SQLAlchemy ... done
Successfully installed Babel-2.6.0 PyMySQL-0.9.3 PyNaCl-1.3.0 SQLAlchemy-1.3.0 amqp-2.4.2 asn1crypto-0.24.0 bcrypt-3.1.6 billiard-3.5.0.5 celery-4.2.1 celery-flower-1.0.1 certifi-2018.11.29 cffi-1.12.2 chardet-3.0.4 cryptography-2.6.1 docker-py-1.10.6 docker-pycreds-0.4.0 fabric-2.4.0 idna-2.8 invoke-1.2.0 kombu-4.4.0 paramiko-2.4.2 psutil-5.6.0 pyasn1-0.4.5 pycparser-2.19 pytz-2018.9 redis-3.2.0 requests-2.21.0 selenium-3.141.0 sh-1.12.14 six-1.12.0 tornado-6.0.1 urllib3-1.24.1 vine-1.2.0 websocket-client-0.55.0 xlrd-1.2.0 xlwt-1.3.0 xmltodict-0.12.0

 

posted @ 2019-03-11 10:37  一个和🔥有缘的人  阅读(8710)  评论(0编辑  收藏  举报