当没有网络

时间:2017-06-27 10:11:56

标签: python caching pip

我想离线安装python包。为此,我使用pip install --cache-dir在线收集它们,然后下一次以相同的方式离线,期望pip将始终读取缓存。

第一次:在线(空缓存,空virtualenv):

~/tmp/venv$ LANG=C pip install --cache-dir /tmp/pipcache matplotlib
Collecting matplotlib
  Downloading matplotlib-2.0.2-cp27-cp27mu-manylinux1_x86_64.whl (14.5MB)
    100% |################################| 14.5MB 99kB/s 
Collecting numpy>=1.7.1 (from matplotlib)
  Downloading numpy-1.13.0-cp27-cp27mu-manylinux1_x86_64.whl (16.6MB)
    100% |################################| 16.6MB 86kB/s 
Collecting cycler>=0.10 (from matplotlib)
  Downloading cycler-0.10.0-py2.py3-none-any.whl
Collecting python-dateutil (from matplotlib)
  Downloading python_dateutil-2.6.0-py2.py3-none-any.whl (194kB)
    100% |################################| 194kB 5.8MB/s 
Collecting functools32 (from matplotlib)
  Downloading functools32-3.2.3-2.zip
Collecting six>=1.10 (from matplotlib)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting pytz (from matplotlib)
  Downloading pytz-2017.2-py2.py3-none-any.whl (484kB)
    100% |################################| 491kB 3.1MB/s 
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 (from matplotlib)
  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
    100% |################################| 61kB 8.8MB/s 
Collecting subprocess32 (from matplotlib)
  Downloading subprocess32-3.2.7.tar.gz (54kB)
    100% |################################| 61kB 8.4MB/s 
Building wheels for collected packages: functools32, subprocess32
  Running setup.py bdist_wheel for functools32 ... done
  Stored in directory: /tmp/pipcache/wheels/3c/d0/09/cd78d0ff4d6cfecfbd730782a7815a4571cd2cd4d2ed6e69d9
  Running setup.py bdist_wheel for subprocess32 ... done
  Stored in directory: /tmp/pipcache/wheels/7d/4c/a4/ce9ceb463dae01f4b95e670abd9afc8d65a45f38012f8030cc
Successfully built functools32 subprocess32
Installing collected packages: numpy, six, cycler, python-dateutil, functools32, pytz, pyparsing, subprocess32, matplotlib
Successfully installed cycler-0.10.0 functools32-3.2.3.post2 matplotlib-2.0.2 numpy-1.13.0 pyparsing-2.2.0 python-dateutil-2.6.0 pytz-2017.2 six-1.10.0 subprocess32-3.2.7

第二次:离线(重用缓存,重新创​​建空virtualenv),一切正常:

~/tmp/venv$ LANG=C pip install --cache-dir /tmp/pipcache matplotlib
Collecting matplotlib
  Using cached matplotlib-2.0.2-cp27-cp27mu-manylinux1_x86_64.whl
Collecting numpy>=1.7.1 (from matplotlib)
  Using cached numpy-1.13.0-cp27-cp27mu-manylinux1_x86_64.whl
Collecting cycler>=0.10 (from matplotlib)
  Using cached cycler-0.10.0-py2.py3-none-any.whl
Collecting python-dateutil (from matplotlib)
  Using cached python_dateutil-2.6.0-py2.py3-none-any.whl
Collecting functools32 (from matplotlib)
Collecting six>=1.10 (from matplotlib)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting pytz (from matplotlib)
  Using cached pytz-2017.2-py2.py3-none-any.whl
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 (from matplotlib)
  Using cached pyparsing-2.2.0-py2.py3-none-any.whl
Collecting subprocess32 (from matplotlib)
Installing collected packages: numpy, six, cycler, python-dateutil, functools32, pytz, pyparsing, subprocess32, matplotlib
Successfully installed cycler-0.10.0 functools32-3.2.3.post2 matplotlib-2.0.2 numpy-1.13.0 pyparsing-2.2.0 python-dateutil-2.6.0 pytz-2017.2 six-1.10.0 subprocess32-3.2.7

第三次:离线(重用缓存,重新创​​建空virtualenv),一些错误:

~/tmp/venv$ LANG=C pip install --cache-dir /tmp/pipcache matplotlib
Collecting matplotlib
  Using cached matplotlib-2.0.2-cp27-cp27mu-manylinux1_x86_64.whl
Collecting numpy>=1.7.1 (from matplotlib)
  Using cached numpy-1.13.0-cp27-cp27mu-manylinux1_x86_64.whl
Collecting cycler>=0.10 (from matplotlib)
  Using cached cycler-0.10.0-py2.py3-none-any.whl
Collecting python-dateutil (from matplotlib)
  Using cached python_dateutil-2.6.0-py2.py3-none-any.whl
Collecting functools32 (from matplotlib)
Collecting six>=1.10 (from matplotlib)
  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f7abfbdbfd0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/six/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f7abfbdb490>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/six/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f7abfbdbf50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/six/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f7ac1068ed0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/six/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f7ac1068910>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/six/
  Could not find a version that satisfies the requirement six>=1.10 (from matplotlib) (from versions: )
No matching distribution found for six>=1.10 (from matplotlib)

存在网络错误:我不知道为什么因为所有包都在缓存中可用。此外,错误是随机的:它可能在安装six或pytz包时发生。有时可能没有任何错误,有时会发生上述情况。

如何更正此问题,以便我可以进行离线安装?

注意:pip和setuptools是最新版本

1 个答案:

答案 0 :(得分:0)

尝试adding the --no-index parameter(也可能--find-links)。

编辑:使用pip downloadpip install -f似乎有效:

$ docker run -it python:3.6 bash

root@06dbe462c2c3:/# cd tmp
root@06dbe462c2c3:/tmp# ls
root@06dbe462c2c3:/tmp# mkdir cache
root@06dbe462c2c3:/tmp# pip download -d cache matplotlib
Successfully downloaded matplotlib pytz numpy six pyparsing cycler python-dateutil
root@06dbe462c2c3:/tmp# pip install --no-index matplotlib
No matching distribution found for matplotlib
root@06dbe462c2c3:/tmp# pip install --no-index matplotlib -f cache/
Collecting matplotlib
Collecting cycler>=0.10 (from matplotlib)
Collecting pyparsing!=2.0.0,!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 (from matplotlib)
Collecting python-dateutil (from matplotlib)
Collecting pytz (from matplotlib)
Collecting numpy>=1.7.1 (from matplotlib)
Collecting six>=1.10 (from matplotlib)
Installing collected packages: six, cycler, pyparsing, python-dateutil, pytz, numpy, matplotlib
Successfully installed cycler-0.10.0 matplotlib-2.0.2 numpy-1.13.0 pyparsing-2.2.0 python-dateutil-2.6.0 pytz-2017.2 six-1.10.0
root@06dbe462c2c3:/tmp#