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