简体   繁体   English

在Windows下构建FANN Python绑定

[英]Building FANN Python bindings under Windows

I tried to compile the python bindings (pyfann) for FANN via python setup.py install . 我试图通过python setup.py install为FANN编译python绑定(pyfann)。 With an installed Visual Studio 2010 and SWIGWIN I get several errors. 使用安装的Visual Studio 2010和SWIGWIN,我会遇到一些错误。

Has anyone a precompiled version of the python bindings for Python 2.7 under Windows 7 and/or 8? 是否有人在Windows 7和/或8下预编译了python 2.7的python绑定版本? I also tried that one pyfann under windows , but the build of _libfann.pyd aborted. 我也尝试在Windows下使用一个pyfann ,但是_libfann.pyd的构建中止了。

I have compiled fann for python 2.7. 我已经为python 2.7编译了fann。
You can download it from here: https://github.com/jacekm-git/pyfann_python2.7_windows 您可以从这里下载: https : //github.com/jacekm-git/pyfann_python2.7_windows

Compilation steps : 编译步骤:

1. Swig installation: 1. Swig安装:

  • download: sourceforge.net/projects/swig/files/swigwin/ 下载:sourceforge.net/projects/swig/files/swigwin/
  • extract files to C:\\swigwin\\ 将文件解压缩到C:\\ swigwin \\
  • edit system path variable 编辑系统路径变量
    • rigth click MyComputer -> properties 右键单击MyComputer->属性
    • "advanced" tab -> "Environment Variables" “高级”选项卡->“环境变量”
    • edit "Path" variable -> add ";C:\\swigwin\\;C:\\python27\\;C:\\python27\\Scripts\\" on the end of the line. 编辑“路径”变量->在行尾添加“; C:\\ swigwin \\; C:\\ python27 \\; C:\\ python27 \\ Scripts \\”。

2. Microsoft Visual C++ Studio 2008 Express: 2. Microsoft Visual C ++ Studio 2008 Express:

  • download and install : go.microsoft.com/?linkid=7729279 下载并安装:go.microsoft.com/?linkid=7729279

3. Fann 2.1 3.范恩2.1

4. Compile fanndoubled.dll 4.编译fanndoubled.dll

  • open C:\\fann\\MicrosoftWindowsDll\\windll.vcproj in Visual C++ Studio 2008 在Visual C ++ Studio 2008中打开C:\\ fann \\ MicrosoftWindowsDll \\ windll.vcproj
  • Build -> Build windll 建立->建立windll
  • copy files fanndoubled.dll, fanndoubled.lib to C:\\fann\\python\\pyfann 将文件fanndoubled.dll,fanndoubled.lib复制到C:\\ fann \\ python \\ pyfann

5. Swig 5.痛饮

  • open command prompt 打开命令提示符

    cd c:\fann\python\pyfann\
    swig -c++ -python pyfann.i
  • open in Visual C++ Studio 2008 C:\\fann\\python\\pyfann.wrap.cxx 在Visual C ++ Studio 2008中打开C:\\ fann \\ python \\ pyfann.wrap.cxx
    • find line( ctrl+f) : SWIGINTERN PyObject *_wrap_training_data_parent_create_train_from_callback 查找行(ctrl + f):SWIGINTERN PyObject * _wrap_training_data_parent_create_train_from_callback


    SWIGINTERN PyObject *_wrap_training_data_parent_create_train_from_callback(PyObject*SWIGUNUSEDPARM(self), PyObject *args) {
      PyObject *resultobj = 0;
      FANN::training_data *arg1 = (FANN::training_data *) 0 ;
      unsigned int arg2 ;
      unsigned int arg3 ;
      unsigned int arg4 ;
      void (*arg5)(unsigned int,unsigned int,unsigned int,fann_type *,fann_type *) = (void (*)(unsigned int,unsigned int,unsigned int,fann_type *,fann_type *)) 0 ;
      // .... rest of file ...

change to: 改成:



    typedef void (__stdcall *arg5_fn)(unsigned int, unsigned int, unsigned int, fann_type*, fann_type*); // added line 
    SWIGINTERN PyObject *_wrap_training_data_parent_create_train_from_callback(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
      PyObject *resultobj = 0;
      FANN::training_data *arg1 = (FANN::training_data *) 0 ;
      unsigned int arg2 ;
      unsigned int arg3 ;
      unsigned int arg4 ;
      /* void (*arg5)(unsigned int,unsigned int,unsigned int,fann_type *,fann_type *) = (void (*)(unsigned int,unsigned int,unsigned int,fann_type *,fann_type *)) 0 ;*/
      arg5_fn arg5= (arg5_fn)NULL; // added line
      // ....

6. setup.py 6. setup.py

  • open in editor C:\\fann\\python\\pyfann\\setup.py 在编辑器C:\\ fann \\ python \\ pyfann \\ setup.py中打开
  • find and comment lines: 查找和注释行:


    # swig_cmd = 'swig -c++ -python pyfann/pyfann.i'
    # print 'Running SWIG before:', swig_cmd
    # os.system(swig_cmd)

  • change setup lines to: 将设置行更改为:


    ext_modules=[Extension('pyfann._libfann',['pyfann/pyfann_wrap.cxx'], 
                            include_dirs=['../src/include'], 
                            # extra_objects=['../src/doublefann.o'], 
                            libraries = ['pyfann/fanndoubled'],
                            define_macros=[("SWIG_COMPILE",None)]
                                ),

7. installation 7.安装



    cd C:\fann\python\
    python setup.py install
    copy C:\fann\python\pyfann\fanndoubled.dll C:\Python27\Lib\site-packages\pyfann\

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM