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

大憨熊 提交于 2020-06-27 07:40:55

问题


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


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/50521033/add-a-custom-wheel-file-as-a-dependency-in-setup-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!