一般公司的服务器都是和外网隔离的,这个如果没有内部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. (from -r python3_modules.txt (line ))
Collecting asn1crypto==0.24. (from -r python3_modules.txt (line ))
Collecting Babel==2.6. (from -r python3_modules.txt (line ))
Collecting bcrypt==3.1. (from -r python3_modules.txt (line ))
Collecting billiard==3.5.0.5 (from -r python3_modules.txt (line ))
Collecting celery==4.2. (from -r python3_modules.txt (line ))
Collecting celery-flower==1.0. (from -r python3_modules.txt (line ))
Collecting certifi==2018.11. (from -r python3_modules.txt (line ))
Collecting cffi==1.12. (from -r python3_modules.txt (line ))
Collecting chardet==3.0. (from -r python3_modules.txt (line ))
Collecting cryptography==2.6. (from -r python3_modules.txt (line ))
Collecting docker-py==1.10. (from -r python3_modules.txt (line ))
Collecting docker-pycreds==0.4. (from -r python3_modules.txt (line ))
Collecting fabric==2.4. (from -r python3_modules.txt (line ))
Collecting idna==2.8 (from -r python3_modules.txt (line ))
Collecting invoke==1.2. (from -r python3_modules.txt (line ))
Collecting kombu==4.4. (from -r python3_modules.txt (line ))
Collecting paramiko==2.4. (from -r python3_modules.txt (line ))
Collecting psutil==5.6. (from -r python3_modules.txt (line ))
Collecting pyasn1==0.4. (from -r python3_modules.txt (line ))
Collecting pycparser==2.19 (from -r python3_modules.txt (line ))
Collecting PyMySQL==0.9. (from -r python3_modules.txt (line ))
Collecting PyNaCl==1.3. (from -r python3_modules.txt (line ))
Collecting pytz==2018.9 (from -r python3_modules.txt (line ))
Collecting redis==3.2. (from -r python3_modules.txt (line ))
Collecting requests==2.21. (from -r python3_modules.txt (line ))
Collecting selenium==3.141. (from -r python3_modules.txt (line ))
Collecting sh==1.12. (from -r python3_modules.txt (line ))
Collecting six==1.12. (from -r python3_modules.txt (line ))
Collecting SQLAlchemy==1.3. (from -r python3_modules.txt (line ))
Collecting tornado==6.0. (from -r python3_modules.txt (line ))
Collecting urllib3==1.24. (from -r python3_modules.txt (line ))
Collecting vine==1.2. (from -r python3_modules.txt (line ))
Collecting websocket-client==0.55. (from -r python3_modules.txt (line ))
Collecting xlrd==1.2. (from -r python3_modules.txt (line ))
Collecting xlwt==1.3. (from -r python3_modules.txt (line ))
Collecting xmltodict==0.12. (from -r python3_modules.txt (line ))
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. PyMySQL-0.9. PyNaCl-1.3. SQLAlchemy-1.3. amqp-2.4. asn1crypto-0.24. bcrypt-3.1. billiard-3.5.0.5 celery-4.2. celery-flower-1.0. certifi-2018.11. cffi-1.12. chardet-3.0. cryptography-2.6. docker-py-1.10. docker-pycreds-0.4. fabric-2.4. idna-2.8 invoke-1.2. kombu-4.4. paramiko-2.4. psutil-5.6. pyasn1-0.4. pycparser-2.19 pytz-2018.9 redis-3.2. requests-2.21. selenium-3.141. sh-1.12. six-1.12. tornado-6.0. urllib3-1.24. vine-1.2. websocket-client-0.55. xlrd-1.2. xlwt-1.3. xmltodict-0.12.

离线方式快速安装python模块以及相关依赖模块的更多相关文章

  1. 在Ubuntu上使用离线方式快速安装K8S v1.11.1

    在Ubuntu上使用离线方式快速安装K8S v1.11.1 0.安装包文件下载 https://pan.baidu.com/s/1nmC94Uh-lIl0slLFeA1-qw v1.11.1 文件大小 ...

  2. 第三百二十三节,web爬虫,scrapy模块以及相关依赖模块安装

    第三百二十三节,web爬虫,scrapy模块以及相关依赖模块安装 当前环境python3.5 ,windows10系统 Linux系统安装 在线安装,会自动安装scrapy模块以及相关依赖模块 pip ...

  3. 二 web爬虫,scrapy模块以及相关依赖模块安装

    当前环境python3.5 ,windows10系统 Linux系统安装 在线安装,会自动安装scrapy模块以及相关依赖模块 pip install Scrapy 手动源码安装,比较麻烦要自己手动安 ...

  4. 二进制方式快速安装MySQL数据库命令集合

    二进制方式快速安装MySQL数据库命令集合 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 1.安装mysql ls mysql ...

  5. CentOS RDO方式快速安装OpenStack

    一.了解RDO RDO是什么? RDO是红帽Red Hat Enterprise Linux OpenStack Platform的社区版,类似RHEL和Fedora,RHEV和oVirt这样的关系. ...

  6. Windows安装Python图像处理库:PIL模块

    平常一般都在Linux下用Python,今天女票突然说让帮忙把一些图片全部弄成一个分辨率的,作为程序员,这种重复的工作还是交给计算机吧. 废话不多说,打开Cmd看下Windows的python下面是否 ...

  7. CentOS 7 yum方式快速安装MongoDB

    一.安装环境及配置yum # more /etc/redhat-release CentOS Linux release 7.2.1511 (Core) # vi /etc/yum.repos.d/m ...

  8. Linux - CentOS 7 yum方式快速安装MongoDB

    一.安装环境及配置yum # more /etc/redhat-release CentOS Linux release 7.2.1511 (Core) # vi /etc/yum.repos.d/m ...

  9. PHP安装扩展mcrypt以及相关依赖项 【PHP安装PECL扩展的方法】

    一:Mcrypt简介 Mcrypt是PHP的一个扩展,完成了常用加密算法的封装.其实该扩展是对mcrypt标准类库的封装,mcrypt完成了相当多的常用加密算法,如DES, TripleDES, Bl ...

随机推荐

  1. IOS—— strong weak retain assign 学习

    转自:http://wenzongliang.iteye.com/blog/1746604 简单讲strong等同retain weak比assign多了一个功能,当对象消失后自动把指针变成nil,好 ...

  2. swagger页面详细讲解

  3. 两个概念:CCA和LDA

    典型相关性分析(CCA) https://blog.csdn.net/Mbx8X9u/article/details/78824216 典型关联分析(Canonical Correlation Ana ...

  4. Python的字符串与字节码转换

    一张图弄懂python的字符串与字节码转换  

  5. yum lockfile is held by another process

    使用yum安装软件报错 yum lockfile is held by another process 解决方法 rm -f /var/run/yum.pid

  6. linux禁止root用户直接登录

    允许root用户登录是很不安全的,但是有时候为了测试的方便, 也可以允许root用户登录,但是这个方法最好不要对公网开放使用. 1.新建一个用户,用来登录 test@cloud:~> usera ...

  7. 【Tomcat】使用Eclipse绑定Tomcat 发布应用&&常见错误

     创建时间:6.14 一.Eclipse绑定Tomcat 步骤1:获得服务器运行环境配置,Window/Preferences/Server/Runtime Environment 步骤2:添加服务器 ...

  8. MySol序

    1.mysql是基于C/S端的服务器软件 mysql服务端: server端开启,对文件的增删改查 , musql客户端::连接S端, 发送指令 isnert into t1 values(1); 2 ...

  9. 【AICC】2019训练营笔记

    1.AI 人工的方法在机器上实现智能:机器学习.计算机视觉.规划决策.自然语言处理.认知推理.高效搜索 2.三大学派 符号主义 连接主义:CNN 行为主义 3.两条路线 结构模仿 功能模仿 4.AI芯 ...

  10. ESA2GJK1DH1K基础篇: 阿里云物联网平台: 测试MQTT连接阿里云物联网平台

    前言 这节看一下在阿里云上实现MQTT通信是个怎样的流程 看了很多网上的教程,感觉讲的迷迷糊糊.... 其实感觉他们是对MQTT不够透彻,所以写的文章就是个比着葫芦画瓢的感觉 在我面前这东西就是玩具. ...