LoginSignup
101
118

More than 5 years have passed since last update.

pip installをオフライン環境で行う方法

Posted at

たまにやる必要が出てくるので、備忘録。
オンライン環境可でのpip installはシンプルに

pip install パッケージ名

で完了。

オフラインへのインストールの場合は、いったんオンライン環境で
pip install --download ダウンロード先 --no-binary :all: パッケージ名
もしくは
pip download -d ダウンロード先 --no-binary :all: パッケージ名

でファイルをダウンロード。
オフライン環境の適当なディレクトリにコピーして、そこに移動。
pip installを行うという流れ。

やってみる

今回はテストとしてopenpyxlで行ってみる。
カレントディレクトリ以下にsrcフォルダを作成して

pip install --download src --no-binary :all: openpyxl
で、ダウンロードすると

DEPRECATION: pip install --download has been deprecated and will be removed in the future. Pip now has a download command that should be used instead.
Collecting openpyxl
  Using cached openpyxl-2.4.8.tar.gz
  Saved ./src/openpyxl-2.4.8.tar.gz
Collecting jdcal (from openpyxl)
  Using cached jdcal-1.3.tar.gz
  Saved ./src/jdcal-1.3.tar.gz
Collecting et_xmlfile (from openpyxl)
  Using cached et_xmlfile-1.0.1.tar.gz
  Saved ./src/et_xmlfile-1.0.1.tar.gz
Successfully downloaded openpyxl jdcal et-xmlfile

ダウンロードは成功するが
DEPRECATION: pip install --download has been deprecated and will be removed in the future. Pip now has a download command that should be used instead.
というメッセージ。
--downloadオプションは廃止される予定なので、downloadコマンド使ってね。ということなので、使えるか試してみる

pip download -d src --no-binary :all: openpyxl

で実行。ちなみに、カレントディレクトリ/srcはDL先としてデフォルトで設定されているので、指定しなくてもOK。他のフォルダ名になっている場合は指定が必要

Collecting src
  Using cached src-0.0.7.zip
  Saved ./src-0.0.7.zip
Collecting openpyxl
  Using cached openpyxl-2.4.8.tar.gz
  Saved ./openpyxl-2.4.8.tar.gz
Collecting jdcal (from openpyxl)
  Using cached jdcal-1.3.tar.gz
  Saved ./jdcal-1.3.tar.gz
Collecting et_xmlfile (from openpyxl)
  Using cached et_xmlfile-1.0.1.tar.gz
  Saved ./et_xmlfile-1.0.1.tar.gz
Successfully downloaded src openpyxl jdcal et-xmlfile

成功。

et_xmlfile-1.0.1.tar.gz
jdcal-1.3.tar.gz
openpyxl-2.4.8.tar.gz

の3つがDLできました。
これを、オフライン環境下の適当なフォルダにコピーして、そのディレクトリに移動。最後に、それぞれpip installを実行すればOK

pip intall et_xmlfile-1.0.1.tar.gz
pip intall jdcal-1.3.tar.gz
pip intall openpyxl-2.4.8.tar.gz

他のオプションはここに色々載っていますね。

101
118
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
101
118