11

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

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

1 Comment

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

3 Comments

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?
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).
We sometimes speak about "abstract" (in setup.py) and "concrete" (in requirements.txt) requirements. See: packaging.python.org/discussions/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.