我想将需求中提到的所有python软件包下载到Linux中的文件夹中.txt。我不想安装它们。我只需要下载它们。
我想编写一个可以下载所有python包的python脚本。
Python 版本是 3.6
要求中的包列表.txt
python-ldap==3.2.0
python-libnmap==0.6.2
python-otrs==0.4.3
pytz==2015.4
PyYAML==3.11
query-string==0.0.2
queuelib==1.2.2
redis==2.10.3
requests==2.22.1
requests-aws4auth==0.9
requests-oauthlib==0.5.0
requests-toolbelt==0.5.0
scp==0.10.2
six==1.10.0
South==1.0.1
tlslite==0.4.9
u-msgpack-python==2.1
urllib3==1.14
w3lib==1.12.0
websockets==3.3
Werkzeug==0.10.4
xlrd==1.0.0
XlsxWriter==1.0.5
zope.interface==4.1.2
GitPython==2.1.3
import subprocess
import sys
command = [
sys.executable,
'-m',
'pip',
'download',
'--dest',
'path/to/target',
'--requirement',
'path/to/requirements.txt',
]
subprocess.check_call(command)
参考资料:
- https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program
- 在代码中安装 python 模块
- https://docs.python.org/3/library/subprocess.html#subprocess.check_call
- https://snarky.ca/why-you-should-use-python-m-pip/
只是下载软件包?
然后你可以使用pip
命令
pip download <package name>==<version>
如果你想做一个python脚本,你可以使用subprocess
subprocess.check_call([sys.executable, '-m', 'pip', 'download',
'<packagename>==<version>'])
通常你会使用:
pip install --target=/path/to/install/to -r requirement.txt
这应该将所需的所有包.txt下载到您指定的路径。