【问题标题】:What does cmdclass do in Pythons setuptools?cmdclass 在 Python 的 setuptools 中做了什么?
【发布时间】:2015-03-05 05:07:57
【问题描述】:

我最近收到了一个拉取请求,其中添加了

class build_ext(_build_ext):
    'to install numpy'
    def finalize_options(self):
        _build_ext.finalize_options(self)
        # Prevent numpy from thinking it is still in its setup process:
        __builtins__.__NUMPY_SETUP__ = False
        import numpy
        self.include_dirs.append(numpy.get_include())

到我的setup.py 导致:

from setuptools.command.build_ext import build_ext as _build_ext

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup


class build_ext(_build_ext):
    'to install numpy'
    def finalize_options(self):
        _build_ext.finalize_options(self)
        # Prevent numpy from thinking it is still in its setup process:
        __builtins__.__NUMPY_SETUP__ = False
        import numpy
        self.include_dirs.append(numpy.get_include())


config = {
    'cmdclass':{'build_ext':build_ext}, #numpy hack
    'setup_requires':['numpy'],         #numpy hack
    'name': 'nntoolkit',
    'version': '0.1.25',
    'author': 'Martin Thoma',
    'author_email': 'info@martin-thoma.de',
    'packages': ['nntoolkit'],
    'scripts': ['bin/nntoolkit'],
    'url': 'https://github.com/MartinThoma/nntoolkit',
    'license': 'MIT',
    'description': 'Neural Network Toolkit',
    'long_description': """...""",
    'install_requires': [
        "argparse",
        "theano",
        "nose",
        "natsort",
        "PyYAML",
        "matplotlib",
        "h5py",
        "numpy",
        "Cython"
    ],
    'keywords': ['Neural Networks', 'Feed-Forward', 'NN', 'MLP'],
    'download_url': 'https://github.com/MartinThoma/nntoolkit',
    'classifiers': ['Development Status :: 3 - Alpha'],
    'zip_safe': False,
    'test_suite': 'nose.collector'
}

setup(**config)

它有什么作用?

documentation 只声明:

cmdclass:命令名称到Command 子类的映射(字典)

【问题讨论】:

  • 明显有错别字。它应该是:'cmdclass':{'build_ext':build_ext}, #numpy hack

标签: python setuptools


【解决方案1】:

Numpy 库是用 C/C++ 编写的。所以与其他包不同的是,它需要在实际调用它们之前进行编译。所以'build_ext'只是编译它们。

博客详情:http://sadafnoor.me/blog/how-to-automate-numpy-installation-in-your-project-using-setuptool/

【讨论】:

  • 我不知道你有博客。恭喜,您有了新订阅者 :-) 我不明白的是这段代码如何找到 C/C++ 源代码。它适用于所有系统(它似乎适用于 Linux Mint。其他发行版怎么样?它适用于 Windows 吗?)
  • 现在页面不见了。
  • @TomaszGandor 这是更新后的 (?) 链接 blog.sadafnoor.me/blog/…
  • 这也不再工作了 :-) 但更多信息可以在这里找到realitix.github.io/python/2016/11/09/python-customize-setup
猜你喜欢
  • 2014-03-21
  • 2019-01-13
  • 2020-10-13
  • 2018-12-04
  • 2011-03-10
  • 1970-01-01
  • 1970-01-01
  • 2013-07-09
  • 2011-06-18
相关资源
最近更新 更多