如何将setup.py包含在构建的发行版中

0 投票
1 回答
1227 浏览
提问于 2025-04-18 14:59

我有一个典型的项目结构,长得像这样:

EngineEmulator        
    ship
        engine
            emulator
            mapping
            __init__.py
        tests
            emulator
            mapping
            __init__.py           
        setup.py
        MANIFEST.in
        setup.cfg
        README.rst

我的setup.py文件长得像这样:

from setuptools import setup, find_packages
setup(
   name='Engine',
   version=1.0.0,
   description='Engine Project',      
   packages=find_packages(
   exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
   install_requires =['pycrypto', 
                      'kombu >=1.1.3'],
   author='Demo',
   author_email='demo@eliza.net'
   license='MIT',
   classifiers=[
    'Topic :: Demo Engine',
    'Development Status:: 3 - Iteration',
    'Programming Language :: Python -2.6'
]

)

我的setup.cfg文件长得像这样:

[egg_info]
tag_build = .dev
tag_svn_revision = 1

[rotate]
#keep last 15 eggs, clean up order
match = .egg
keep = 15   

还有我的MANIFEST.in文件长得像这样:

include README.rst
include setup.py
recursive-include engine *

当我运行 python setup.py bdist 时,它生成的tar文件里没有setup.py文件。 当我用pip安装时,它就会提示找不到setup.py文件。 但是当我运行 python setup.py sdist 时,它生成的tar文件里却有setup.py。 你知道这是为什么吗?

1 个回答

4

Pip 不支持安装Distutils的傻瓜式bdist格式的分发包。更通用的分发格式是sdist格式,这种格式通常可以在任何Python环境中“构建”以便安装。sdist通常是上传到PyPI的文件,特别是对于纯Python的分发包,比如那些不包含需要在目标系统上编译的C代码的包。目前版本的pip也可以安装wheels,这是一种智能的bdist格式,可以包含纯Python的分发包或针对特定平台的混合分发包。

撰写回答