|
1 | 1 | import sys |
2 | | -import numpy |
3 | 2 | import setuptools |
4 | 3 | from distutils.core import setup |
5 | 4 | from distutils.extension import Extension |
|
10 | 9 | module_name1 = 'maxflow' |
11 | 10 | maxflow_source = "maxflow_python/wrap_py{0:}.cpp".format(py_version) |
12 | 11 | module1 = Extension(module_name1, |
13 | | - include_dirs = [numpy.get_include(),'./dependency', './maxflow_python'], |
| 12 | + include_dirs = ['./dependency', './maxflow_python'], |
14 | 13 | sources = ['maxflow_python/maxflow.cpp', |
15 | 14 | 'maxflow_python/util.cpp', |
16 | 15 | 'dependency/maxflow-v3.0/graph.cpp', |
|
20 | 19 | module_name2 = 'denseCRF' |
21 | 20 | densecrf_source = "densecrf_python/wrap2D_py{0:}.cpp".format(py_version) |
22 | 21 | module2 = Extension(module_name2, |
23 | | - include_dirs = [numpy.get_include(), |
| 22 | + include_dirs = [ |
24 | 23 | './dependency/densecrf/include', |
25 | 24 | './dependency/densecrf/external/liblbfgs/include'], |
26 | 25 | sources=['./densecrf_python/densecrf.cpp', |
|
40 | 39 | module_name3 = 'denseCRF3D' |
41 | 40 | densecrf_source = "densecrf_python/wrap3D_py{0:}.cpp".format(py_version) |
42 | 41 | module3 = Extension(module_name3, |
43 | | - include_dirs = [numpy.get_include(), |
| 42 | + include_dirs = [ |
44 | 43 | './dependency/densecrf3d/include', |
45 | 44 | './dependency/densecrf/external/liblbfgs/include'], |
46 | 45 | sources=['./densecrf_python/densecrf3d.cpp', |
|
69 | 68 | with open('README.md', encoding='utf-8') as f: |
70 | 69 | long_description = f.read() |
71 | 70 |
|
| 71 | +from setuptools.command.build_ext import build_ext |
| 72 | + |
| 73 | +class CustomBuildExtCommand(build_ext): |
| 74 | + """build_ext command for use when numpy headers are needed.""" |
| 75 | + def run(self): |
| 76 | + |
| 77 | + # Import numpy here, only when headers are needed |
| 78 | + import numpy |
| 79 | + |
| 80 | + # Add numpy headers to include_dirs |
| 81 | + self.include_dirs.append(numpy.get_include()) |
| 82 | + |
| 83 | + # Call original build_ext command |
| 84 | + build_ext.run(self) |
72 | 85 |
|
73 | 86 | setup(name=package_name, |
74 | 87 | version = "0.1.1", |
|
87 | 100 | 'Programming Language :: Python :: 2', |
88 | 101 | 'Programming Language :: Python :: 3', |
89 | 102 | ], |
90 | | - python_requires = '>=3.6') |
| 103 | + python_requires = '>=3.6', |
| 104 | + cmdclass = {'build_ext': CustomBuildExtCommand}, |
| 105 | + install_requires=['numpy'], |
| 106 | + ) |
91 | 107 |
|
92 | 108 |
|
93 | 109 | # to build, run python stup.py build or python setup.py build_ext --inplace |
|
0 commit comments