I’m writing a setup script for a python distribution, foo. My code requires BeautifulSoup, so currently my directory is structured like so:
<root>/
setup.py
__init__.py
foo.py
BeautifulSoup/
__init__.py
BeautifulSoup.py
etc.
And setup.py currently looks like this (less meta info):
setup(name='foo',
version='0.9.0',
py_modules=['foo']
)
I want to include BeautifulSoup in case the user doesn’t have it installed already, but I also don’t want to install it if they already have it installed at a particular version. I noticed in the Python 2.7.2 docs that I should included packages=[...] in my setup.py file.
However, Section 2.4. Relationships between Distributions and Packages mentions that there’s a way to specify that a particular version of the package is required. I couldn’t find any examples of how to use a “requires expression” within setup.py, so I’m not sure if this is what I need.
In short, I need a way to say:
This package requires
BeautifulSoup, with at least X.X.X version. If that version isn’t installed, use the one that’s provided.
How do I do that?
Directory structure:
Note: there is no
__init__.pyfile.You could use
distributeto specify dependencies,setup.py:This will install required version of
BeautifulSoupif it is not already present. You don’t need to provideBeautifulSoupin this case.If you don’t want to install
BeautifulSoupautomatically:setup.py:
Somewhere in in your modules:
It is a less desirable and unusual method.