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.
The following works as expected:
pip3 download virtualenv --platform win_amd64 -d py_packages_20180222/ --only-binary=:all:
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)
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?
EDIT: 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)
No, according to the pip documentation, such an option does not exist:
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):