Ted
Ted

Reputation: 73

Conditionally installing a wheel file using pip

I'm trying to get pip to install numpy from different sources according to the user's platform. I'm trying to achieve that by using "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 fine when I'm on Linux, but when I'm on Windows pip searches for the file - that doesn't even have a proper file path on Windows - even though it's protected by "platform_system".

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

The installation then stops.

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

Upvotes: 3

Views: 390

Answers (1)

Pedro Boechat
Pedro Boechat

Reputation: 2576

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

What you can do, however, is make pip continue the installation if the file is not found.

Just change your requirement from:

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

to:

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

With --find-links pip will then enter another control flow where the URI is evaluated at a later point and only cause a warning to be printed if it's invalid or if the resource is not found.

EDIT:

I just realized that --find-links doesn't work with single requirements in a requirements.txt.

Since you're not simply installing different packages for each platform, but rather installing different packages from different sources for each platform, I'd suggest separating the platform specific requirements into different files (i.e.: requirements_Windows.txt and requirements_Linux.txt) and running "pip install -r" differently on each platform.

On Windows, you could have a local package repository built with i.e. pip2pi and then run:

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

Upvotes: 1

Related Questions