所以我有一个类似这样的文件夹结构:
pckA - core
- io
pckB - core
- io
- main
现在我必须为这两个包创建一个 setup.py 文件。我目前的方法是:
from distutils.core import setup
import setuptools
setup(
name='ProjectExternals',
version='0.1dev',
packages=["pckA","pckA.core","pckA.io","pckB","pckB.core","pckB.io","pckB.main"],
license='Not decided yet',
author='',
author_email='',
long_description="",
install_requires=["numpy","quantities"]
)
这个 setup.py 与 pckA 和 pckB 位于同一文件夹中。所以我的问题是:是否有必要添加所有子包,如 pckA.core 等,或者 setuptools 是否也知道安装这些子包?
最佳答案
不,如果您只想要整个包,指定其名称(即 pckA
)就足够了 - 无需列出其中的所有模块。 distutils
将递归地发现它们。
所以在你的情况下:
packages=['pckA', 'pckB'],
成功了。这是来自 the docs 的引用:
<小时/>The packages option tells the Distutils to process (build, distribute, install, etc.) all pure Python modules found in each package mentioned in the packages list. In order to do this, of course, there has to be a correspondence between package names and directories in the filesystem.
如果您不想要整个包,而只想包含特定模块,请改用py_modules
选项。
关于python setup.py问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5945914/