How to instruct pip to install a requirement with --no-binary flag

Viewed 2317

I have an app that I want to package which is dependent on protobuf. It is essential that protobuf be installed as such:

pip install protobuf --no-binary=protobuf protobuf

How can I include this inside my setup.py install_requires?

Note: My requirements mandate that this process automatically goes through setup.py.

I am aware of this and this

Thus, I've tried including such things in install_requires or requirements.txt to no luck:

#requirements.txt
protobuf
--no-binary=protobuf

How can I provide the --no-binary=protobuf protobuf (which I know are pip flags) to the installation of protobuf when I'm packaging my app?

Update: What I want is for the protobuf package to be installed the way I mentioned when I install my package this way:

`pip install my_package.whl`
1 Answers

Install with a requirements.txt file

I guess you can simply add the flag on the same line. This worked for me:

# requirements.txt

protobuf --no-binary protobuf
pandas

With this requirements.txt, protobuf is installed without binaries, whereas pandas is still installed with .whl.

By running pip install -r requirements.txt, you will have something like:

$ pip install -r requirements.txt 
Collecting pandas
  ...
Collecting protobuf
  Using cached protobuf-3.17.3.tar.gz (228 kB)
Skipping wheel build for protobuf, due to binaries being disabled for it.
Installing collected packages: protobuf, pandas
    Running setup.py install for protobuf ... done
Successfully installed pandas-1.1.5 protobuf-3.17.3

Automatic install inside a packaged library

If you want to include the dependency to protobuf with no binary, and you are packaging your library with a setup.py file, you can include package@http://link/to/package.tar.gz inside the install_requires argument of setup.

from setuptools import setup, find_packages

setup(
    name='your package`,
    version='0.1',
    packages=find_packages(),
    install_requires=[
        'click',
        'pyyaml',
        'protobuf@https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protobuf-python-3.17.3.tar.gz'
    ]
)

This solution's drawback is that it also specifies the the version of the dependency.

Hope this helps !

Related