Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a custom wheel file as a dependency in setup.py?

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

like image 416
JustinBlaber Avatar asked May 25 '18 03:05

JustinBlaber


2 Answers

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
like image 57
dolbi Avatar answered Sep 29 '22 19:09

dolbi


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
like image 29
Laurent LAPORTE Avatar answered Sep 29 '22 20:09

Laurent LAPORTE