我最近收到了一个请求,它增加了
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)是干什么的呢?
文档只声明:
cmdclass:命令名到命令子类的映射(字典)
发布于 2015-01-07 13:29:37
Numpy库是用C/C++编写的。因此,与其他包不同的是,它需要在实际调用它们之前进行编译。所以'build_ext‘只是编译它们。
博客详细信息:http://sadafnoor.me/blog/how-to-automate-numpy-installation-in-your-project-using-setuptool/
发布于 2022-10-20 20:18:19
所有的骗局:
我发现另一个博客很好地解释了这一点:
https://niteo.co/blog/setuptools-run-custom-code-in-setup-py
对studioj也大喊大叫;这一页解释了同样的事情,但是对于distutils而不是setuptools (它们的定义非常相似)。
本质上,它们创建类来覆盖setuptools/distutils使用的各种命令(特别是它们的".run“命令)。
例如,如果要在setuptools中覆盖"build“命令,可以使用如下模式:
from setuptools import setup
from setuptools.command.build import build
class MyBuild(build):
def run(self):
# ---- some custom code here ----
# important to do this instead of "super", since it hasn't been properly updated
build.run(self)
setup(
# setup specifications here
cmdclass={"build": MyBuild}
)https://stackoverflow.com/questions/27817190
复制相似问题