Conditionally set the wheel file using pip

I am trying to get pip to install numpy from various sources according to the custom platform. I am trying to achieve this using the "platform_system" environment marker.

# requirements.txt

# installing from a local wheel file
/python35/wheels_repo/numpy-1.12.0.whl;platform_system == "Linux"
# installing from PyPi
numpy==1.12.0;platform_system == "Windows"

      

It works great when I'm on Linux, but when I'm on Windows, a file looks for a file that doesn't even have the correct file path on Windows, even if it is protected by "platform_system".

Requirement '/python35/wheels_repo/numpy-1.12.0.whl' looks like a filename, but the file does not exist

      

Then the installation stops.

Is there a way to make pip not look for this file, or at least resume the installation if the file is not found?

+3


source to share


1 answer


I believe pip will always check for the existence of a file. And this check is done before the installation requirements are checked (i.e., if the environment labels match).

However, you can have pip continue to install if the file is not found.

Just change your requirement:

/python35/wheels_repo/numpy-1.12.0.whl;platform_system == "Linux"

      

in

--find-links "file:///python35/wheels_repo/" numpy-1.12.0.whl;platform_system == "Linux"

      



With -find-links pip will inject a different flow of control where the URI is evaluated at a later point and only issues a printable warning if it is invalid or if the resource is not found.

EDIT:

I just realized that -find links do not work with single requirements in the requirements file.

Since you are not just installing different packages for each platform, but installing different packages from different sources for each platform, I would suggest separating the platform requirements into different files (ie: requirements_Windows.txt and requirements_Linux.txt) and run "pip install - r "is different on each platform.

On Windows, you can create a local package repository built with pip2pi and then run:

pip install --extra-index-url file://[path-to-your-local-package-repository]/simple -r requirements_Windows.txt

      

0


source







All Articles