Pythonは40の環境輸送凍結生成requirements.txtノート

序文

私たちは、Pythonのプロジェクトオートメーションユースケースを完了するために、ローカルコンピュータ上のpython開発を使用するか、Djangoのプロジェクトを開発しました。
別のコンピュータまたはサーバーにデプロイする必要が、パイソン関連のライブラリをインポートする必要がフリーズキーファイルrequirements.txt生成することができた場合

  • ピップフリーズ> requirements.txt#が移行ファイルを生成します
  • インストールピップ-r requirements.txt#依存関係をインストール

Makefileを凍結

例えば、私はローカルコンピュータのpythonを開発するプロジェクトを完了し、それは、サードパーティ製のパッケージの多くが参加する、との問題もなく、過去の移行を確保するために、バージョン番号は、対応していました。
この機能では少し愚かな感じ、私は最初にすべてのサードパーティのパッケージを表示するには、リストをピップとき、私は凍結を知らないし、その後1つのピップずつをインストールします。
requirements.txtプロジェクトファイル内の参照、他の人から、私はピップがによって生成されたキーを凍結することを実現しました

ピップフリーズ> 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 ~]# 

現在のプロジェクトを含むすべてのサードパーティ製のパッケージと、現在のディレクトリにrequirements.txtファイルを生成するバージョン番号は、アウトつながります

インストールPIP

requirements.txtファイル生成した後、我々は1つのピップずつインストールする必要はありません、ピップは、キーのインストール、現在のディレクトリにrequirements.txtファイルで使用することができます

ピップ-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 ~]# 

ローカルインストール

あなたの会社のサーバーをダウンロードするには、ネットワークを制限する場合は、あなただけのローカルパッケージのインストールをダウンロードすることができますローカル、凍結してインストールすることができます。
サーバが何のネットワークが存在しないと仮定され、あなたがサーバーのpythonにサードパーティ製のパッケージをインストールする必要があり、その後、あなたも最初のネットワークサーバB、サーバB上のインストールパッケージをダウンロードする最初の必要性を見つけることができます

サーバーは、インストールパッケージBをダウンロード

最初の使用は、パッケージをインストールする必要がどこにでも凍結PIP、例えば、私は次のパッケージをインストールしたいです

[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インストールパッケージをダウンロードしてください

ピップダウンロード-r requirements.txt

アリはクラウドサーバであれば、mirrors.aliyun.com --trustedホストにパラメータを追加し、次のエラーが表示されます。

[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ホストmirrors.aliyun.comパラメータ

ピップダウンロード-r requirements.txt --trustedホスト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

ローカルサーバーにインストールされています

サーバーA上できませんネットワーキング、あなたは、あなたがローカルにインストールピップを使用することができ、リポジトリAに上記の最初の関連パッケージをダウンロードすることができます。
.Whlサフィックスパッケージが直接ローカルにインストールをピップ使用することができます。

ピップpytest-3.6.3-py2.py3-なし-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システム上でエクスポートしたパッケージ、インストールはLinux上で失敗した可能性があります)

おすすめ

転載: www.cnblogs.com/yoyoketang/p/11409978.html