一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

python筆記40-環(huán)境遷移freeze生成requirements.txt

 上海悠悠 2021-05-27

前言

我們用python在本地電腦上開發(fā)完成一個python自動化項目用例,或者開發(fā)完成一個django項目。
需要部署到另外一臺電腦或者服務(wù)器上的時候,需要導(dǎo)入python相關(guān)的依賴包,可以用freeze一鍵生成requirements.txt文件

  • pip freeze >requirements.txt  #  生成一個遷移文件

  • pip install -r requirements.txt           #   安裝依賴包

freeze生成文件

比如我在本地電腦開發(fā)完成了python的一個項目,會涉及到很多第三方的包,并且版本號都得一一對應(yīng),這樣才能保證遷移過去不會有問題。
在不知道freeze這個功能的時候,我是先pip list 查看所有的第三方包,然后一個個pip安裝,感覺挺傻的。
自從看到別人項目里面有個requirements.txt文件,才知道原來可以通過pip freeze一鍵生成

pip freeze >requirements.txt

[root@yoyo ~]# pip freeze >requirements.txt
[root@yoyo ~]# cat requirements.txt
APScheduler==3.5.3
asn1crypto==0.24.0
# ....太多省略了
xlrd==1.2.0
xlwt==1.3.0
[root@yoyo ~]#

這樣在當(dāng)前目錄就會生成一個requirements.txt文件,包當(dāng)前項目的所有第三方包和版本號都會導(dǎo)出來

pip 安裝

requirements.txt文件生成后,我們不需要一個個pip安裝,可以在requirements.txt文件當(dāng)前目錄使用pip一鍵安裝

pip install -r requirements.txt

[root@yoyo ~]# pip install -r requirements.txt
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: APScheduler==3.5.3 in /usr/local/python3/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (3.5.3)
Requirement already satisfied: asn1crypto==0.24.0 in /usr/local/python3/lib/python3.6/site-packages (from -r requirements.txt (line 2)) (0.24.0)
Requirement already satisfied: atomicwrites==1.3.0 in /usr/local/python3/lib/python3.6/site-packages (from -r requirements.txt (line 3)) (1.3.0)
# ....太多省略了
Requirement already satisfied: xlwt==1.3.0 in /usr/local/python3/lib/python3.6/site-packages (from -r requirements.txt (line 62)) (1.3.0)
Requirement already satisfied: setuptools>=0.7 in /usr/local/python3/lib/python3.6/site-packages (from APScheduler==3.5.3->-r requirements.txt (line 1)) (40.6.2)
[root@yoyo ~]#

本地安裝

如果你們公司的服務(wù)器限制了網(wǎng)絡(luò)下載,那么只能通過本地安裝了,freeze也可以下載本地包安裝。
假設(shè)A服務(wù)器是沒有網(wǎng)絡(luò)的,你需要在A服務(wù)器上安裝python第三方包,那么你先找個可以連網(wǎng)絡(luò)的服務(wù)器B,在服務(wù)器B上先下載需要的安裝包

服務(wù)器B上下載安裝包

先使用pip freeze到處需要安裝的包,比如我想安裝以下包

[root@yoyo site-pkg]# cat requirements.txt
ix==1.12.0
attrs==18.2.0
py==1.7.0
pluggy==0.6.0
atomicwrites==1.3.0
more-itertools==6.0.0
pytest==3.6.3

pip download下載相關(guān)安裝包

pip download -r requirements.txt

如果是阿里云服務(wù)器,會出現(xiàn)如下報錯,那么加個參數(shù)—trusted-host mirrors.aliyun.com即可

[root@yoyo site-pkg]# pip download -r requirements.txt
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting ix==1.12.0 (from -r requirements.txt (line 1))
The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored.
If this repository is available via HTTPS we recommend you use HTTPS instead,
otherwise you may silence this warning and allow it anyway with '--trusted-host mirrors.aliyun.com'.
Could not find a version that satisfies the requirement ix==1.12.0 (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for ix==1.12.0 (from -r requirements.txt (line 1))
You are using pip version 18.1, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

加上—trusted-host mirrors.aliyun.com參數(shù)

pip download -r requirements.txt —trusted-host mirrors.aliyun.com

[root@yoyo site-pkg]# pip download -r requirements.txt --trusted-host mirrors.aliyun.com
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting six==1.12.0 (from -r requirements.txt (line 1))
File was already downloaded /root/site-pkg/six-1.12.0-py2.py3-none-any.whl
Collecting attrs==18.2.0 (from -r requirements.txt (line 2))
Downloading http://mirrors.aliyun.com/pypi/packages/3a/e1/5f9023cc983f1a628a8c2fd051ad19e76ff7b142a0faf329336f9a62a514/attrs-18.2.0-py2.py3-none-any.whl
Saved ./attrs-18.2.0-py2.py3-none-any.whl
Successfully downloaded six attrs py pluggy atomicwrites more-itertools pytest setuptools
[root@yoyo site-pkg]# ll
total 968
-rw-r--r-- 1 root root 5885 Aug 25 23:17 atomicwrites-1.3.0-py2.py3-none-any.whl
-rw-r--r-- 1 root root 34713 Aug 25 23:17 attrs-18.2.0-py2.py3-none-any.whl
-rw-r--r-- 1 root root 52353 Aug 25 23:17 more_itertools-6.0.0-py3-none-any.whl
-rw-r--r-- 1 root root 13723 Aug 25 23:17 pluggy-0.6.0-py3-none-any.whl
-rw-r--r-- 1 root root 83960 Aug 25 23:17 py-1.7.0-py2.py3-none-any.whl
-rw-r--r-- 1 root root 195787 Aug 25 23:17 pytest-3.6.3-py2.py3-none-any.whl
-rw-r--r-- 1 root root 106 Aug 25 23:16 requirements.txt
-rw-r--r-- 1 root root 576332 Aug 25 23:17 setuptools-41.2.0-py2.py3-none-any.whl
-rw-r--r-- 1 root root 10586 Aug 25 23:17 six-1.12.0-py2.py3-none-any.whl
[root@yoyo site-pkg]#

這樣就可以下載到.whl后綴的本地包了

服務(wù)器A上本地安裝

由于服務(wù)器A上無法聯(lián)網(wǎng),可以先把上面下載到的相關(guān)包傳到服務(wù)器A上,然后就可以使用pip本地安裝了.
.whl后綴的包是可以直接使用pip本地安裝的。

pip install pytest-3.6.3-py2.py3-none-any.whl

[root@yoyo site-pkg]# pip install pytest-3.6.3-py2.py3-none-any.whl
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: pytest==3.6.3 from file:///root/site-pkg/pytest-3.6.3-py2.py3-none-any.whl in /usr/local/python3/lib/python3.6/site-packages (3.6.3)
Requirement already satisfied: pluggy<0.7,>=0.5 in /usr/local/python3/lib/python3.6/site-packages (from pytest==3.6.3) (0.6.0)
Requirement already satisfied: six>=1.10.0 in /usr/local/python3/lib/python3.6/site-packages (from pytest==3.6.3) (1.12.0)
Requirement already satisfied: atomicwrites>=1.0 in /usr/local/python3/lib/python3.6/site-packages (from pytest==3.6.3) (1.3.0)
Requirement already satisfied: more-itertools>=4.0.0 in /usr/local/python3/lib/python3.6/site-packages (from pytest==3.6.3) (6.0.0)
Requirement already satisfied: attrs>=17.4.0 in /usr/local/python3/lib/python3.6/site-packages (from pytest==3.6.3) (18.2.0)
Requirement already satisfied: py>=1.5.0 in /usr/local/python3/lib/python3.6/site-packages (from pytest==3.6.3) (1.7.0)
Requirement already satisfied: setuptools in /usr/local/python3/lib/python3.6/site-packages (from pytest==3.6.3) (40.6.2)
[root@yoyo site-pkg]#

如果安裝過程中有的包會有其他的依賴包,需先安裝依賴包,一個個的安裝就可以了。
(注意:windows系統(tǒng)上導(dǎo)出的包,在linux上安裝可能會有失敗的)

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    日本免费一本一二区三区| 国产精品一区二区传媒蜜臀| 久久综合九色综合欧美| 色婷婷成人精品综合一区| 日韩一级一片内射视频4k| 99久久精品午夜一区| 国产日韩欧美在线播放| 日韩色婷婷综合在线观看| 日韩欧美一区二区久久婷婷| 色一情一乱一区二区三区码| 91天堂免费在线观看| av在线免费播放一区二区| 国产欧美日韩综合精品二区| 日本不卡在线一区二区三区| 激情内射亚洲一区二区三区| 最近日韩在线免费黄片| 成人精品视频一区二区在线观看| 黄男女激情一区二区三区| 日韩毛片视频免费观看| 日本成人三级在线播放| 国产精品美女午夜福利| 欧美午夜一级特黄大片| 日韩欧美精品一区二区三区| 女人精品内射国产99| 欧美一区二区三区十区| 欧美午夜不卡在线观看| 日韩美女偷拍视频久久| 综合久综合久综合久久| 国产日韩欧美国产欧美日韩| 午夜传媒视频免费在线观看| 激情丁香激情五月婷婷| 中文字幕不卡欧美在线| 中文字幕中文字幕在线十八区 | 欧美日韩视频中文字幕| 香蕉网尹人综合在线观看| 中文字幕一区二区熟女| 国产精品亚洲一区二区| 亚洲第一区二区三区女厕偷拍| 成人国产一区二区三区精品麻豆| 日本久久中文字幕免费| 熟女中文字幕一区二区三区|