11

Some useful Python packages are broken on pypi, and the only acceptable version is a particular revision in a revision control system. Can that be expressed in setup.py e.g

requires = 'svn://example.org/useful.package/trunk@1234' ?

4 Answers 4

12

You need to do two things. First, require the exact version you want, e.g.:

install_requires = "useful.package==1.9dev-r1234"

and then include a dependency_links setting specifying where to find it:

dependency_links = ["svn://example.org/useful.package/trunk@1234#egg=useful.package-1.9dev-r1234"]

Note that the version #egg= part of the dependency_links URL must exactly match what you specified in install_requires; this is what links the two pieces together.

What happens is that setuptools sees the #egg tag on the link and saves the URL as an available download URL for that precise version of the package. Then, when it tries to resolve that requirement later, it should download that precise SVN URL.

(Note, however, that for this to really work, the targeted SVN revision has to actually build an egg with that name and version. Otherwise, your dependency will fail at runtime! So, this really only works if the package you're depending on uses SVN revision tags in their default build version numbers.)

3
  • 1
    Yep, it doesn't /really/ work in the common case... I just use pip now.
    – joeforker
    Mar 15, 2010 at 20:55
  • shouldn't "find_links" actually be "dependency_links" ? Dec 19, 2010 at 12:58
  • The #egg= part of your dependency_links url doesn't exactly match what you specified in install_requires: it uses a - where your install_requires uses a ==. Which parts of the string must match exactly?
    – oadams
    Jan 21, 2020 at 14:46
2

If you really require an obscure version of another package, and there's no way to make do with other versions, you might want to simply distribute that version of the package with your own. If necessary put it in your own namespace to ensure that your version is the one that is used.

2

I haven't figured out how to reference this from setup.py but pip can check out specific revisions of Python packages with a simple requirements file. With a requirements file called requires.txt, pip install -r requires.txt will install all the packages listed in that file (and their dependencies).

Here is part of my requirements file. The lines starting with -e check out specific revisions of packages from version control (git, svn, or mercurial), including my project, and install them in an editable form. pip freeze lists all installed packages in this format.

requires.txt:

-e hg+file:///home/me/my-private-project#egg=myproject
-e hg+http://bitbucket.org/ianb/webob@tip#egg=WebOb
-e svn+http://svn.sqlalchemy.org/sqlalchemy/trunk@6638#egg=SQLAlchemy
-e svn+http://svn.zope.org/repos/main/z3c.saconfig/trunk@106508#egg=z3c.saconfig
## The following requirements were added by pip --freeze:
APScheduler==1.01
simplejson==2.0.9
... (many more)
1
  • Do you really want to have editable form of your dependencies? Jun 1, 2012 at 19:06
1

You can release packages of specific versions, but you have to distribute them together. There is no way to automatically download them with standard Python.

However, you can use Buildout and create a buildout.cfg that makes it possible to replicate the environment. It can check out and install specific revisions if you use extensions like mr.developer.

http://pypi.python.org/pypi/zc.buildout http://pypi.python.org/pypi/mr.developer

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.