9

I'm working on a project where one of the dependencies is actually a .whl that isn't on pypi (i.e. I had to download the wheel direct from the author and pip install it directly). In my setup.py file, is there a way to do something like:

install_requires=[
    'library.whl',
    'matplotlib==2.2.2',
    'numpy==1.14.2',
    'opencv-python==3.4.0.12',
    'Pillow==5.1.0',
    'PyYAML==3.12',
],

Or something along these lines since its not on pypi (and I would just add the library.whl in the MANIFEST.in file or something)? If not, is there a recommended way to do this for this type of situation? I'd ideally like to solve this in the setup.py file so I can install my library easily with a single pip install

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
JustinBlaber
  • 4,629
  • 2
  • 36
  • 57

2 Answers2

3

As provided in the comment use this answer for more information.

TL;DR:

setup(
    ...
    install_requires=[
         'repo @ https://github.com/user/archive/master.zip#egg=repo-1.0.0'],
    ...
)

DEPRECATED:

According to the docs, you need to specify dependency_links in your setup arguments:

DEPRECATED
Community
  • 1
  • 1
dolbi
  • 2,180
  • 1
  • 19
  • 25
  • 1
    Deprecated. See more: https://stackoverflow.com/questions/12518499/pip-ignores-dependency-links-in-setup-py#comment94736800_13587734 – Sanctus Aug 02 '19 at 15:56
2

One alternative is to use a pip requirement files to install your dependencies. A requirement file specify each library and required version. You can use a URL to point to your wheel.

Example:

http://host/path/to/library.whl
matplotlib==2.2.2
numpy==1.14.2
opencv-python==3.4.0.12
Pillow==5.1.0
PyYAML==3.12

And simply specify ‘library’ to your setup.py file.

Edit

The best practice is to have an additional PyPi server like DevPi. And change your pip configuration file to add this repository. Of course your library.whl must be pushed in this private server.

Example of pip.conf:

[global]
index-url = http://yourserver/group/user/

[install]
trusted-host = yourserver

[download]
trusted-host = yourserver

[list]
format = columns

You may also need to configure your .pypirc file:

[distutils]
index-servers = pypi
                private

[pypi]
repository: http://pypi.python.org/pypi
username:your-username
password:your-password

[private]
repository: http://yourserver
username:your-login
password:your-password

That way you could push your releases on your private server:

python setup.py bdist_wheel upload -r private register -r private
Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103
  • What do you mean by "And simply specify ‘library’ to your setup.py file." ? If I provide a `requirements.txt` file does that mean people have to download it and then do `pip install -r requirements.txt`? Or can I supply a `requirements.txt` to my `setup.py` file somehow? – JustinBlaber May 25 '18 at 15:14
  • In your `setup.py` you need to specify the minimum requirements for the application to work, so "library" is required. The `requirements.txt` usually specify the exact requirements with fixed versions. Note: the 2nd solution is better (the one with a private repository). – Laurent LAPORTE May 25 '18 at 15:18
  • We sometimes speak about "abstract" (in `setup.py`) and "concrete" (in `requirements.txt`) requirements. See: https://packaging.python.org/discussions/install-requires-vs-requirements/ – Laurent LAPORTE May 25 '18 at 15:22