Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass build_ext options to pip install

Tags:

Is there some way to pass build_ext options to pip install to alter how an extension included in a package is compiled? (Yes, I know that one can download the source and build/install with a custom setup.cfg, but I'm curious whether it is possible to pass options that can be specified in setup.cfg directly through pip.)

like image 361
lebedov Avatar asked Mar 31 '13 02:03

lebedov


People also ask

How do I apply a specific package to pip?

How do I Install a Specific Version of a Python Package? To install a specific version of a Python package you can use pip: pip install YourPackage==YourVersion . For example, if you want to install an older version of Pandas you can do as follows: pip install pandas==1.1. 3 .

What is U option in pip install?

1 Answer. This option upgrades all packages. From man pip /INSTALL OPTIONS: -U, --upgrade Upgrade all packages to the newest available version.

Does pip install all dependencies?

Pip relies on package authors to stipulate the dependencies for their code in order to successfully download and install the package plus all required dependencies from the Python Package Index (PyPI).


1 Answers

It's possible using pip --global-option=build_ext.

For example this is requirements.txt for Pillow with PNG and JPEG support and no other external libraries:

pillow \         --global-option="build_ext" \         --global-option="--enable-zlib" \         --global-option="--enable-jpeg" \         --global-option="--disable-tiff" \         --global-option="--disable-freetype" \         --global-option="--disable-tcl" \         --global-option="--disable-tk" \          --global-option="--disable-lcms" \         --global-option="--disable-webp" \         --global-option="--disable-webpmux" \         --global-option="--disable-jpeg2000" 

This is really an abuse of pip --global-option, inspired by this answer, as build_ext is a pip command and not really a global pip option. But this would make pip to execute two commands — first build_ext and then install — like this:

pip \     build_ext \         --enable-zlib --enable-jpeg \         --disable-tiff --disable-freetype --disable-tcl --disable-tk \         --disable-lcms --disable-webp --disable-webpmux --disable-jpeg2000 \     install pillow 
like image 123
Tometzky Avatar answered Sep 22 '22 23:09

Tometzky