你具体想做什么?除非您有一些奇怪的要求,否则我建议您在 setup.py 中将包声明为依赖项:
from setuptools import setup, find_packages
setup(
name = "HelloWorld",
version = "0.1",
packages = find_packages(),
scripts = ['say_hello.py'],
# Project uses reStructuredText, so ensure that the docutils get
# installed or upgraded on the target machine
install_requires = ['docutils>=0.3'],
package_data = {
# If any package contains *.txt or *.rst files, include them:
'': ['*.txt', '*.rst'],
# And include any *.msg files found in the 'hello' package, too:
'hello': ['*.msg'],
}
# metadata for upload to PyPI
author = "Me",
author_email = "me@example.com",
description = "This is an Example Package",
license = "PSF",
keywords = "hello world example examples",
url = "http://example.com/HelloWorld/", # project home page, if any
# could also include long_description, download_url, classifiers, etc.
)
这里的关键行是install_requires = ['docutils>=0.3']。除非用户另外指定,否则这将导致 setup.py 文件自动安装此依赖项。您可以在 here 上找到更多文档(请注意 setuptools 网站非常慢!)。
如果您确实有某种无法通过这种方式满足的要求,您可能应该查看S.Lott's answer(尽管我自己从未尝试过)。