首页 > 解决方案 > 如何使用 pip3 安装如果我已经有包裹,则离线

问题描述

我可以安装一个本地包,如下所示:

....,root,root # /usr/bin/pip3 install PyYAML-5.3.tar.gz
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Processing ./PyYAML-5.3.tar.gz
Installing collected packages: PyYAML
  Found existing installation: PyYAML 3.13
    Uninstalling PyYAML-3.13:
      Successfully uninstalled PyYAML-3.13
  Running setup.py install for PyYAML ... done
Successfully installed PyYAML-5.3
....,root,root #

但是如果我尝试下面的命令它会失败,因为它会在互联网上搜索(我的虚拟机没有互联网连接)

,root,root # /usr/bin/pip3 install PyYAML==5.3
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting PyYAML==5.3
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17164e0080>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pyyaml/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17164e0198>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pyyaml/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17164e0278>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pyyaml/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17164e0358>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pyyaml/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17164e0400>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pyyaml/
  Could not find a version that satisfies the requirement PyYAML==5.3 (from versions: )
No matching distribution found for PyYAML==5.3
.....,root,root #

所以问题是将我下载的包“PyYAML-5.3.tar.gz”放在默认位置以使此命令(/usr/bin/pip3 install PyYAML==5.3)在本地而不是在互联网上查找它?

标签: pythonlinuxpip

解决方案


推荐阅读