Installing from custom index setup.py

2019-07-31 03:16发布

问题:

I am the package maintainer of a package that has dependencies to packages hosted in our own pip repository.

I want these packages to also be installed when doing pip install mypackage.

setup(
  name='mypackage',
  version='1.1.2',
  description='My awesome package',
  dependency_links=[
    'http://www.myrepo.se/packages/mydep1/',
    'http://www.myrepo.se/packages/mydep2/'
  ]
  install_requires=[
    'mydep1==1.0.0',
    'mydep2==5.6.7'
  ]
)

The folder structure in the repo is the following:

packages/
  mydep1/
    mydep1-1.0.0.tar.gz
  mydep2/
    mydep2-5.5.1.tar.gz
    mydep2-5.6.7.tar.gz

All according to the accepted answer on this question Using an extra python package index url with setup.py

However, this does not work. I get the error:

Collecting mydep1 (from mypackage==1.1.2)
  Could not find a version that satisfies the requirement mydep1 (from mypackage==1.1.2) (from versions: )
No matching distribution found for mydep1 (from mypackage==1.1.2)

When I have added an extra index url to my requirements.txt before doing it this was I had to add the url as a trusted host. Is that relevant? Also I am using python 3.5.3

EDIT: I activated verbose output from pip and it is not even trying to find the package from my repo.

1 location(s) to search for versions of mydep1:
  * https://pypi.python.org/simple/mydep1/
  Getting page https://pypi.python.org/simple/mydep1/
  ...

回答1:

It seems pip is not processing the dependency links unless you explicitly tell it to (which unfortunately means that all consumers of mypackage must know to do so).

pip install --process-dependency-links mypackage

Since mypackage is also hosted by the same repository it means that a consumers requirements.txt must look like

--trusted-host http://www.myrepo.se/
--extra-index-url http://www.myrepo.se/packages
--process-dependency-links

mypackage==1.1.2