[Distutils] [issue139] pkg_resources.require can't deal with multiple installed versions if one is present in easy-install.pth

PJ Eby pje at telecommunity.com
Mon Jun 25 18:34:20 CEST 2012


On Mon, Jun 25, 2012 at 3:53 AM, mbogosian <setuptools at bugs.python.org>wrote:

>
> Perhaps I have misunderstood the intended behavior, but I thought one
> should be able to do this:
>
> % easy_install BeautifulSoup==3.0.8
> ...
> % easy_install -U BeautifulSoup
> [installs 3.1.0.1]
> ...
> % python -c 'import pkg_resources ; print
> pkg_resources.require("BeautifulSoup==3.0.8")'
> Traceback (most recent call last):
> pkg_resources.VersionConflict: (BeautifulSoup 3.1.0.1
> (.../site-packages/BeautifulSoup-3.1.0.1-py2.5.egg),
> Requirement.parse('BeautifulSoup==3.0.8'))
>

Do this instead:

python -c '__requires__=['BeautifulSoup==3.0.8']; import pkg_resources;
import beautifulsoup'

That is, if the main script declares a __requires__ variable before
importing pkg_resources, pkg_resources will allow you to override what
would normally produce a VersionConflict due to a default version being
present on the command line.

This is an undocumented but supported workaround for the issue, as it's
used internally by the scripts easy_install generates.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20120625/3c9a976d/attachment.html>


More information about the Distutils-SIG mailing list