python 基於各種真實運行環境離線下載安裝包的通用方法

最近經常開發人工智能相關項目,經常需要安裝不通硬件平臺不同操作系統版本不同python版本的各種包,
耗費了大量的時間和精力都是在下載等待中,要麼就是失敗重試.

總結了一套通用的方法,可以節省大量的時間精力,避免精力和時間白白浪費了。特別是在中國境內,下載很慢,即使用了阿里和清華的鏡像源頭,還是下載很慢,因爲少量的包在國內鏡像上沒有,下載速度只有幾KB/秒。

執行辦法:

  1. git clone https://github.com/HappyFreeAngel/create-python-offline-packages.git
  2. 把你需要下載的包和對應的版本放在create-python-offline-packages/requirements.txt
  3. 替換你的docker鏡像文件 默認是: base_docker_image=“python:3.7-buster”
    比如 我在樹莓派raspberry pi3B+上的鏡像是 #base_docker_image=“ascs/iot-env-base:raspberrypi3-opencv4.0.1-tesseract5.0.0-alpha-python3.5.3-python2.7.13”
    這樣你就可以確保可以順利下載各種離線python安裝包。

然後執行create-python-offline-packages/run.sh 即可
即可

[root@proud-hat-2 create-python-offline-packages]# ./run.sh
最新版本請見 https://github.com/HappyFreeAngel/create-python-offline-packages.git
“離線下載python包”
the /root/html/create-python-offline-packages/download 不存在
python 安裝包的信息 requirements.txt 請放在當前目錄download目錄下
python-package-download
python-package-download
0c47c6d645c7d90e0e107a8a9babd794c31f726e72338d7d3f5cd073084a6f0c
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Requirement already up-to-date: pip in /usr/local/lib/python3.7/site-packages (19.2.1)
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting scikit-image==0.15.0 (from -r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2e/21/ea56c8bb2e8112837dd71aebeb2ac67913e784911c0d7f493a593fa1a207/scikit_image-0.15.0-cp37-cp37m-manylinux1_x86_64.whl (26.3MB)
  Saved ./scikit_image-0.15.0-cp37-cp37m-manylinux1_x86_64.whl
Collecting pillow>=4.3.0 (from scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a4/da/2bd281c875686230eabc13d20ab590ea617563b0e746abfb0698c4d5b645/Pillow-6.1.0-cp37-cp37m-manylinux1_x86_64.whl (2.1MB)
  Saved ./Pillow-6.1.0-cp37-cp37m-manylinux1_x86_64.whl
Collecting PyWavelets>=0.4.0 (from scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e3/91/607449f27a3a068739498eddf921cf2686f0a71fa8b44a8efce0af9446a8/PyWavelets-1.0.3-cp37-cp37m-manylinux1_x86_64.whl (4.4MB)
  Saved ./PyWavelets-1.0.3-cp37-cp37m-manylinux1_x86_64.whl
Collecting matplotlib!=3.0.0,>=2.0.0 (from scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/19/7a/60bd79c5d79559150f8bba866dd7d434f0a170312e4d15e8aefa5faba294/matplotlib-3.1.1-cp37-cp37m-manylinux1_x86_64.whl (13.1MB)
  Saved ./matplotlib-3.1.1-cp37-cp37m-manylinux1_x86_64.whl
Collecting scipy>=0.17.0 (from scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5d/bd/c0feba81fb60e231cf40fc8a322ed5873c90ef7711795508692b1481a4ae/scipy-1.3.0-cp37-cp37m-manylinux1_x86_64.whl (25.2MB)
  Saved ./scipy-1.3.0-cp37-cp37m-manylinux1_x86_64.whl
Collecting imageio>=2.0.1 (from scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/af/0a/943c965d372dae0b1f1482677d29030ab834351a61a9a632fd62f27f1523/imageio-2.5.0-py3-none-any.whl (3.3MB)
  Saved ./imageio-2.5.0-py3-none-any.whl
Collecting networkx>=2.0 (from scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/85/08/f20aef11d4c343b557e5de6b9548761811eb16e438cee3d32b1c66c8566b/networkx-2.3.zip (1.7MB)
  Saved ./networkx-2.3.zip
Collecting numpy>=1.9.1 (from PyWavelets>=0.4.0->scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/05/4b/55cfbfd3e5e85016eeef9f21c0ec809d978706a0d60b62cc28aeec8c792f/numpy-1.17.0-cp37-cp37m-manylinux1_x86_64.whl (20.3MB)
  Saved ./numpy-1.17.0-cp37-cp37m-manylinux1_x86_64.whl
Collecting python-dateutil>=2.1 (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl (226kB)
  Saved ./python_dateutil-2.8.0-py2.py3-none-any.whl
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/11/fa/0160cd525c62d7abd076a070ff02b2b94de589f1a9789774f17d7c54058e/pyparsing-2.4.2-py2.py3-none-any.whl (65kB)
  Saved ./pyparsing-2.4.2-py2.py3-none-any.whl
Collecting kiwisolver>=1.0.1 (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/93/f8/518fb0bb89860eea6ff1b96483fbd9236d5ee991485d0f3eceff1770f654/kiwisolver-1.1.0-cp37-cp37m-manylinux1_x86_64.whl (90kB)
  Saved ./kiwisolver-1.1.0-cp37-cp37m-manylinux1_x86_64.whl
Collecting cycler>=0.10 (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
  Saved ./cycler-0.10.0-py2.py3-none-any.whl
Collecting decorator>=4.3.0 (from networkx>=2.0->scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5f/88/0075e461560a1e750a0dcbf77f1d9de775028c37a19a346a6c565a257399/decorator-4.4.0-py2.py3-none-any.whl
  Saved ./decorator-4.4.0-py2.py3-none-any.whl
Collecting six>=1.5 (from python-dateutil>=2.1->matplotlib!=3.0.0,>=2.0.0->scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
  Saved ./six-1.12.0-py2.py3-none-any.whl
Collecting setuptools (from kiwisolver>=1.0.1->matplotlib!=3.0.0,>=2.0.0->scikit-image==0.15.0->-r requirements.txt (line 1))
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl (575kB)
  Saved ./setuptools-41.0.1-py2.py3-none-any.whl
Successfully downloaded scikit-image pillow PyWavelets matplotlib scipy imageio networkx numpy python-dateutil pyparsing kiwisolver cycler decorator six setuptools
[root@proud-hat-2 create-python-offline-packages]# ls
autodownload.sh  download  downloaded-packages  download-python-packages.sh  requirements.txt  run.sh
[root@proud-hat-2 create-python-offline-packages]# ls download-packages
ls: 無法訪問download-packages: 沒有那個文件或目錄
[root@proud-hat-2 create-python-offline-packages]# ls
autodownload.sh  download  downloaded-packages  download-python-packages.sh  requirements.txt  run.sh
[root@proud-hat-2 create-python-offline-packages]# ls downloaded-packages
cycler-0.10.0-py2.py3-none-any.whl    kiwisolver-1.1.0-cp37-cp37m-manylinux1_x86_64.whl  Pillow-6.1.0-cp37-cp37m-manylinux1_x86_64.whl      requirements.txt                                      six-1.12.0-py2.py3-none-any.whl
decorator-4.4.0-py2.py3-none-any.whl  matplotlib-3.1.1-cp37-cp37m-manylinux1_x86_64.whl  pyparsing-2.4.2-py2.py3-none-any.whl               scikit_image-0.15.0-cp37-cp37m-manylinux1_x86_64.whl
download-python-packages.sh           networkx-2.3.zip                                   python_dateutil-2.8.0-py2.py3-none-any.whl         scipy-1.3.0-cp37-cp37m-manylinux1_x86_64.whl
imageio-2.5.0-py3-none-any.whl        numpy-1.17.0-cp37-cp37m-manylinux1_x86_64.whl      PyWavelets-1.0.3-cp37-cp37m-manylinux1_x86_64.whl  setuptools-41.0.1-py2.py3-none-any.whl
[root@proud-hat-2 create-python-offline-packages]#
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章