LoginSignup
7
9

More than 5 years have passed since last update.

mlpyをpython3.3(64bit)でビルド(windows 64bit)

Last updated at Posted at 2014-06-24

mlpyをwindows 64bit環境でビルド

mlpyのwindows用バイナリは32bit用しか提供されないので、自力でビルドします
使用環境:

  • python3.3.5(64bit)
  • windows7 64bit sp1
  • Visual Studio 2010

準備

必要なライブラリを入手

  • numpy
  • scipy
  • GSL

numpy, scipyのインストール

mlpyを使おうとしているなら既にインストールされていると思います。
ない場合は、pip install numpy scipyでインストールしてください

GSLのビルド

スタティックライブラリが必要になります。
私は半年以上前に別件でGSLをビルドしていたのですが、現在は状況が変わっているようです。

以前

私がやった時は、以下のリンクを参考にしました。意外と簡単に出来ました。

現在

現在では、visual studioのプロジェクトへのリンクが消滅しています。
バージョンが少し古いですが、gsl-1.15-vc10.zipを配布しているページは見つかりました。
また、All in Oneパッケージらしきもの(gnu-gsl-for-windows)がありました。
どちらも利用していないので、本当に利用可能かはわかりません。
※2014/7/3追記:gnu-gsl-for-windowsは予想通り使えました。

mlpyの修正

64bit環境用にソースコードを修正します。

setup.pyの"win32""win-amd64"に変更。ただし、25行目はそのまま

before

setup.py(29-41行)
#### libs
if get_platform() == "win32":
   gsl_lib = ['gsl', 'cblas']
   math_lib = []
else:
   gsl_lib = ['gsl', 'gslcblas']
   math_lib = ['m']

#### Extra compile args
if get_platform() == "win32":
   extra_compile_args = []
else:
   extra_compile_args = ['-Wno-strict-prototypes']

after

setup.py(29-41行)
#### libs
if get_platform() == "win-amd64":
   gsl_lib = ['gsl', 'cblas']
   math_lib = []
else:
   gsl_lib = ['gsl', 'gslcblas']
   math_lib = ['m']

#### Extra compile args
if get_platform() == "win-amd64":
   extra_compile_args = []
else:
   extra_compile_args = ['-Wno-strict-prototypes']

コメントの2バイト文字を修正。Θと二重引用符(”)を削除

before

mlpy/fastcluster/fastcluster/src/fastcluster.cpp(630-632行)
    // Complexity: Θ(size)
    // Reference: Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms,
    // 3rd ed., 2009, Section 6.3 “Building a heap”

after
コメントを削除

np.int_tnp.int64_tに変更

修正をしないとint型とlong long型の不一致による実行時エラーが発生してTutorialすら実行できません。
他にも修正が必要な個所があるかもしれませんが、今のところ発見できていません
before

mlpy/libsvm/libsvm.pyx(28-32行)
# array 1D to svm node
cdef svm_node *array1d_to_node(np.ndarray[np.float64_t, ndim=1] x):
    cdef int i, k
    cdef np.ndarray[np.int_t, ndim=1] nz
    cdef svm_node *ret

after

mlpy/libsvm/libsvm.pyx(28-32行)
# array 1D to svm node
cdef svm_node *array1d_to_node(np.ndarray[np.float64_t, ndim=1] x):
    cdef int i, k
    cdef np.ndarray[np.int64_t, ndim=1] nz
    cdef svm_node *ret

before

mlpy/adatron/adatron.pyx(69-73行)

        cdef np.ndarray[np.int_t, ndim=1] ynew
        cdef np.ndarray[np.float_t, ndim=2] K_arr
        cdef np.ndarray[np.float_t, ndim=1] alpha_arr
        cdef double margin

after

mlpy/adatron/adatron.pyx(69-73行)

        cdef np.ndarray[np.int64_t, ndim=1] ynew
        cdef np.ndarray[np.float_t, ndim=2] K_arr
        cdef np.ndarray[np.float_t, ndim=1] alpha_arr
        cdef double margin

mlpyのビルド

お待たせしました
あとは

set LIB=%LIB%;(gsl.lib,cblas.libがあるディレクトリ)
python setup.py build_ext --include-dirs=(gslのインクルードディレクトリ)
python setup.py install

もしくは(anacondaをインストールした場合)
python setup.py build_ext --include-dirs=(gslのインクルードディレクトリ) --compiler=msvc install

で完了です。
お疲れ様でした。

7
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
9