離線方式快速安裝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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM