Greg Nisbet
Greg Nisbet

Reputation: 6994

Pip install only pure-python packages

Is there a way to configure pip to install only pure-python packages with pure-python dependencies? I'd like to be able to write a python project that is compatible with both Jython and CPython.

Upvotes: 2

Views: 1614

Answers (2)

oliversen
oliversen

Reputation: 11

pip install -t ./bundled/libs --only-binary :all: --implementation py --abi none --platform any -r ./requirements.txt

This pip command will install dependencies from requirements.txt file into ./bundled/libs folder using Pure Python Wheels. The disadvantage is that the packages must be uploaded on PyPI as wheel archives. But 99.5% of the most downloaded packages on PyPI have wheels.

Upvotes: 1

Greg Nisbet
Greg Nisbet

Reputation: 6994

Looking through the file that implements the various command line options for pip and reading the documentation, it would appear that none of these options have the ability to exclude packages based on this criterion. --no-binary and --only-binary seem to deal with compilation in general rather than excluding packages with non-python content.

https://github.com/pypa/pip/blob/de6e4b5c9ea942e6c961066f1ad7f5398b730dfa/pip/cmdoptions.py

The python wheel PEP has metadata that shows what part of the package is a purelib and gets expanded into site-packages, and a Root-Is-Purelib boolean field which seems to indicate that the entire package is pure python. https://www.python.org/dev/peps/pep-0491/ It might be possible to configure pip to exclude everything but wheels and then filter the wheels based on metadata.

The deprecated --use-wheel flag seems to cause pip to prefer wheels, but not to exclude non-wheels. There does not seem to be a way to block wheels from being installed based on their metadata.

Upvotes: 4

Related Questions