質問編集履歴
1
ソースコードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,4 +3,151 @@
|
|
3
3
|
cyvlfeatをpipでインストールしなくてはいけない状況になり、以下サイトを参考にgithubからcyvlfeatをローカルにダウンロードして使おうと思ったのですが、リンクのサイトの「setup.py, cyvlfeat/init.pyの修正」で行っていることがよくわかりませんでした。
|
4
4
|
|
5
5
|
setup.pyとcyvlfeat/init.pyそれぞれにどのようなコードをどこに追加すればいいか教えていただきたいです。
|
6
|
-
[https://qiita.com/knok/items/598052d17d0f1b26f77a](https://qiita.com/knok/items/598052d17d0f1b26f77a)
|
6
|
+
[https://qiita.com/knok/items/598052d17d0f1b26f77a](https://qiita.com/knok/items/598052d17d0f1b26f77a)
|
7
|
+
|
8
|
+
### 該当のソースコード
|
9
|
+
|
10
|
+
```python
|
11
|
+
import os
|
12
|
+
import platform
|
13
|
+
import site
|
14
|
+
|
15
|
+
from setuptools import setup, find_packages, Extension
|
16
|
+
|
17
|
+
|
18
|
+
SYS_PLATFORM = platform.system().lower()
|
19
|
+
IS_LINUX = 'linux' in SYS_PLATFORM
|
20
|
+
IS_OSX = 'darwin' == SYS_PLATFORM
|
21
|
+
IS_WIN = 'windows' == SYS_PLATFORM
|
22
|
+
|
23
|
+
|
24
|
+
# Get Numpy include path without importing it
|
25
|
+
NUMPY_INC_PATHS = [os.path.join(r, 'numpy', 'core', 'include')
|
26
|
+
for r in site.getsitepackages() if
|
27
|
+
os.path.isdir(os.path.join(r, 'numpy', 'core', 'include'))]
|
28
|
+
if len(NUMPY_INC_PATHS) == 0:
|
29
|
+
try:
|
30
|
+
import numpy as np
|
31
|
+
except ImportError:
|
32
|
+
raise ValueError("Could not find numpy include dir and numpy not installed before build - "
|
33
|
+
"cannot proceed with compilation of cython modules.")
|
34
|
+
else:
|
35
|
+
# just ask numpy for it's include dir
|
36
|
+
NUMPY_INC_PATHS = [np.get_include()]
|
37
|
+
|
38
|
+
elif len(NUMPY_INC_PATHS) > 1:
|
39
|
+
print("Found {} numpy include dirs: "
|
40
|
+
"{}".format(len(NUMPY_INC_PATHS), ', '.join(NUMPY_INC_PATHS)))
|
41
|
+
print("Taking first (highest precedence on path): {}".format(
|
42
|
+
NUMPY_INC_PATHS[0]))
|
43
|
+
NUMPY_INC_PATH = NUMPY_INC_PATHS[0]
|
44
|
+
|
45
|
+
|
46
|
+
# ---- C/C++ EXTENSIONS ---- #
|
47
|
+
# Stolen (and modified) from the Cython documentation:
|
48
|
+
# http://cython.readthedocs.io/en/latest/src/reference/compilation.html
|
49
|
+
def no_cythonize(extensions, **_ignore):
|
50
|
+
import os.path as op
|
51
|
+
for extension in extensions:
|
52
|
+
sources = []
|
53
|
+
for sfile in extension.sources:
|
54
|
+
path, ext = os.path.splitext(sfile)
|
55
|
+
if ext in ('.pyx', '.py'):
|
56
|
+
if extension.language == 'c++':
|
57
|
+
ext = '.cpp'
|
58
|
+
else:
|
59
|
+
ext = '.c'
|
60
|
+
sfile = path + ext
|
61
|
+
if not op.exists(sfile):
|
62
|
+
raise ValueError('Cannot find pre-compiled source file '
|
63
|
+
'({}) - please install Cython'.format(sfile))
|
64
|
+
sources.append(sfile)
|
65
|
+
extension.sources[:] = sources
|
66
|
+
return extensions
|
67
|
+
|
68
|
+
|
69
|
+
def build_extension_from_pyx(pyx_path, extra_sources_paths=None):
|
70
|
+
# If we are building from the conda folder,
|
71
|
+
# then we know we can manually copy some files around
|
72
|
+
# because we have control of the setup. If you are
|
73
|
+
# building this manually or pip installing, you must satisfy
|
74
|
+
# that the vlfeat vl folder is on the PATH (for the headers)
|
75
|
+
# and that the vl.dll file is visible to the build system
|
76
|
+
# as well.
|
77
|
+
include_dirs = [NUMPY_INC_PATH]
|
78
|
+
library_dirs = []
|
79
|
+
if IS_WIN:
|
80
|
+
include_dirs.append(os.environ['LIBRARY_INC'])
|
81
|
+
library_dirs.append(os.environ['LIBRARY_BIN'])
|
82
|
+
|
83
|
+
if extra_sources_paths is None:
|
84
|
+
extra_sources_paths = []
|
85
|
+
extra_sources_paths.insert(0, pyx_path)
|
86
|
+
ext = Extension(name=pyx_path[:-4].replace('/', '.'),
|
87
|
+
sources=extra_sources_paths,
|
88
|
+
include_dirs=include_dirs,
|
89
|
+
library_dirs=library_dirs,
|
90
|
+
libraries=['vl'],
|
91
|
+
language='c')
|
92
|
+
if IS_LINUX or IS_OSX:
|
93
|
+
ext.extra_compile_args.append('-Wno-unused-function')
|
94
|
+
if IS_OSX:
|
95
|
+
ext.extra_link_args.append('-headerpad_max_install_names')
|
96
|
+
return ext
|
97
|
+
|
98
|
+
|
99
|
+
try:
|
100
|
+
from Cython.Build import cythonize
|
101
|
+
except ImportError:
|
102
|
+
import warnings
|
103
|
+
cythonize = no_cythonize
|
104
|
+
warnings.warn('Unable to import Cython - attempting to build using the '
|
105
|
+
'pre-compiled C++ files.')
|
106
|
+
|
107
|
+
|
108
|
+
cython_modules = [
|
109
|
+
build_extension_from_pyx('cyvlfeat/fisher/cyfisher.pyx'),
|
110
|
+
build_extension_from_pyx('cyvlfeat/generic/generic.pyx'),
|
111
|
+
build_extension_from_pyx('cyvlfeat/gmm/cygmm.pyx'),
|
112
|
+
build_extension_from_pyx('cyvlfeat/hog/cyhog.pyx'),
|
113
|
+
build_extension_from_pyx('cyvlfeat/kmeans/cykmeans.pyx'),
|
114
|
+
build_extension_from_pyx('cyvlfeat/quickshift/cyquickshift.pyx'),
|
115
|
+
build_extension_from_pyx('cyvlfeat/sift/cysift.pyx'),
|
116
|
+
build_extension_from_pyx('cyvlfeat/vlad/cyvlad.pyx'),
|
117
|
+
]
|
118
|
+
cython_exts = cythonize(cython_modules, quiet=True)
|
119
|
+
|
120
|
+
|
121
|
+
def get_version_and_cmdclass(package_name):
|
122
|
+
import os
|
123
|
+
from importlib.util import module_from_spec, spec_from_file_location
|
124
|
+
spec = spec_from_file_location('version',
|
125
|
+
os.path.join(package_name, '_version.py'))
|
126
|
+
module = module_from_spec(spec)
|
127
|
+
spec.loader.exec_module(module)
|
128
|
+
return module.__version__, module.cmdclass
|
129
|
+
|
130
|
+
|
131
|
+
version, cmdclass = get_version_and_cmdclass('cyvlfeat')
|
132
|
+
setup(
|
133
|
+
name='cyvlfeat',
|
134
|
+
version=version,
|
135
|
+
cmdclass=cmdclass,
|
136
|
+
description='Cython wrapper of the VLFeat toolkit',
|
137
|
+
url='https://github.com/menpo/cyvlfeat',
|
138
|
+
author='Patrick Snape',
|
139
|
+
author_email='patricksnape@gmail.com',
|
140
|
+
ext_modules=cython_exts,
|
141
|
+
package_data={'cyvlfeat': ['data/*.mat', 'data/ascent.descr', 'data/ascent.frame']},
|
142
|
+
packages=find_packages()
|
143
|
+
)
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
### 試したこと
|
148
|
+
|
149
|
+
ここに問題に対して試したことを記載してください。
|
150
|
+
|
151
|
+
### 補足情報(FW/ツールのバージョンなど)
|
152
|
+
|
153
|
+
ここにより詳細な情報を記載してください。
|