如何使用pip下载可用的Windows二进制文件以及所有其他源文件 [英] How to download available Windows binaries with pip, and source for all else
问题描述
我必须管理两个单独的Python设置,一个在具有Internet连接的Linux机器上,一个在离线Windows机器上.对于给定的一组必需软件包,我想在Linux机器上下载必要文件,然后将它们传输到Windows机器并在此处安装.
I have to administrate two separate Python setups, one on a Linux Machine with internet connection, and one offline Windows machine. For a given set of required packages, I would like to download the necessary files on the Linux machine, transfer them to the Windows machine and install them there.
以下按预期工作:
pip3 download virtualenv --platform win_amd64 -d py_packages_20180222/ --only-binary=:all:
文件virtualenv-15.1.0-py2.py3-none-any.whl
已下载到所需位置,并准备传输.但是,如果pip找不到二进制文件,则会产生错误:
The file virtualenv-15.1.0-py2.py3-none-any.whl
is downloaded to the desired location, and ready for transfer. However, if pip doesn't find a binary file, it produces an error:
pip3 download ipython --platform win_amd64 -d py_packages_20180222/ --only-binary=:all:
Could not find a version that satisfies the requirement simplegeneric>0.8 (from ipython) (from versions: )
No matching distribution found for simplegeneric>0.8 (from ipython)
由于设置--only-binary=:all:
,这是预期的输出,但是这不是我想要的输出.在这种情况下,我希望pip
代替下载源代码(带有警告)并继续.我实质上是在寻找pip
选项--only-binary=:if_available:
.是否存在?
This is the expected output due to the setting --only-binary=:all:
, however it is not my desired output. In such a case, I would like pip
to download the source code instead (with a warning) and continue. I'm essentially looking for the pip
option --only-binary=:if_available:
. Does this exist?
不,不是.感谢接受的答案,我能够使用以下bash脚本找到解决方案:
No, it doesn't. Thanks to the accepted answer, I was able to find my solution in using the following bash script:
#!/usr/bin/env python3
import subprocess
pkges = ['virtualenv',
'ipython']
for pkg in pkges:
cmd = ['pip3',
'download',
pkg,
'--platform',
'win_amd64',
'-d py_packages_20180222/',
'--only-binary=:all:']
result = subprocess.run(cmd)
if result.returncode != 0:
print("No binary found for pkg. Downlaoding source code instead")
cmdalt = ['pip3',
'download',
pkg,
'-d py_packages_20180222/']
subprocess.run(cmdalt)
推荐答案
否,根据 pip文档,这样的选项不存在:
No, according to the pip documentation, such an option does not exist:
--only-binary <format_control>
:请勿使用源程序包.可以多次提供,每次都增加到现有值.接受:all:禁用所有源软件包,:none:清空集合,或者接受一个或多个软件包名称,并且它们之间用逗号分隔.如果没有二进制分发包,则在使用此选项时将无法安装.
--only-binary <format_control>
: Do not use source packages. Can be supplied multiple times, and each time adds to the existing value. Accepts either :all: to disable all source packages, :none: to empty the set, or one or more package names with commas between them. Packages without binary distributions will fail to install when this option is used on them.
您可以在一个小的脚本中用一个条件来达到预期的效果,也许像这样(这只是一个草图,但是我不是Python专家):
You could achieve the desired effect with a conditional in a small script, maybe something like this (this is just a sketch and I'm not a Python expert, though):
#!/usr/bin/env python3
import subprocess
cmd = ['pip3',
'download',
'ipython',
'--platform',
'win_amd64',
'-d py_packages_20180222/',
'--only-binary=:all:']
result = subprocess.run(cmd)
if result.returncode != 0:
print("oh noes")
# put here what should happen if the download of the binaries fails
这篇关于如何使用pip下载可用的Windows二进制文件以及所有其他源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!