CythonGSL/在Windows上通过Cython使用GSL [英] CythonGSL/ Using GSL on Windows via Cython

查看:93
本文介绍了CythonGSL/在Windows上通过Cython使用GSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

机器配置:我的配置是Windows 7 x64,安装了python 2.7和cython 0.18(全部64位).我还安装了MS C ++ 2008 Visual Studio.

Machine Configuration: My config is windows 7 x64, with python 2.7 and cython 0.18 (all 64 bit ) installed. I also have MS C++ 2008 Visual Studio installed.

我有GSL二进制文件,并且路径指向GSL \ Bin.

I have the GSL binaries and have Path pointed to the GSL\Bin.

我正在使用MS VS 2008 + SDK 7.0来编译cython .pyx文件.我使用SDK 7.0命令提示符将其编译为c和cython.

I am using MS VS 2008 + SDK 7.0 to compile cython .pyx files. I use the SDK 7.0 command prompt to compile to c and cython.

问题但是,在编译时,我收到LINK错误2019,这表明未在GSL文件夹中找到头文件.

Problem However at compilation time I get a LINK error 2019, which indicates the header files in the GSL folder are not being found .

我的尝试为了解决这个问题,我下载了CythonGSL.使用来自cythonGSL cimport *"无效.我转到了该软件包的init文件,并更改了它似乎正在搜索的目录以适合我安装GSL的位置.我已经更新了CythonGSL自述文件中显示的setup.py.

My Attempts To resolve this I downloaded CythonGSL. using "from cythonGSL cimport *" didnt work. I went to the init file for this package and changed the directories it appears to be searching for to fit where I have installed GSL. I have updated the setup.py as shown on the CythonGSL readme.

无效!编译时,它说找不到gsl.lib.

This hasnt worked either!! At compile time, it says gsl.lib not found.

有什么主意我可以解决这个问题吗?

Any idea how i can fix this?

一种选择是,例如,我可以指向一个静态地址来代替

One option is if I could point a static address for example, in place of

    cdef extern from "libcalg/queue.h":
       with
    cdef extern from "FUll File Path/queue.h":

暂时不起作用.

setup.py

from distutils.core import setup
from Cython.Distutils import Extension
from Cython.Distutils import build_ext
import cython_gsl
import numpy as np
setup(

    include_dirs = [cython_gsl.get_include(), np.get_include()],
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("lda_gibbs_cython",
                             ["lda_gibbs_cython.pyx"],
                             libraries=cython_gsl.get_libraries(),
                             library_dirs=[cython_gsl.get_library_dir()],
                             include_dirs=[cython_gsl.get_cython_include_dir()])]
    )

唯一的区别是我包含np.get_include()

The only difference is I include np.get _include()

我的.pyx文件:(从 https:/借来进行测试/github.com/twiecki/CythonGSL/blob/master/examples/gibbs.pyx )

My .pyx file : (borrowed for testing from https://github.com/twiecki/CythonGSL/blob/master/examples/gibbs.pyx )

import numpy as np
cimport numpy as np
cimport cython
DTYPE = np.int
ctypedef np.int_t DTYPE_t
from scipy.special import gammaln
from cython_gsl cimport *

cdef gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937)

来自Cython GSL尝试的错误消息:

Error message from the Cython GSL attempt:

D:\LDA\pythonLDA>setup.py build_ext --inplace
running build_ext
cythoning lda_gibbs_cython.pyx to lda_gibbs_cython.c
building 'lda_gibbs_cython' extension
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\Bin\amd64\cl.exe /c /nolog
o /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python27\lib\site-packages -IC:/GSL/include -IC
:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Pytho
n27\PC /Tclda_gibbs_cython.c /Fobuild\temp.win-amd64-2.7\Release\lda_gibbs_cytho
n.obj
lda_gibbs_cython.c
c:\python27\lib\site-packages\numpy\core\include\numpy\npy_deprecated_api.h(8) :
 Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECA
TED_API NPY_1_7_API_VERSION
lda_gibbs_cython.c(2812) : warning C4244: 'function' : conversion from '__int64'
 to 'long', possible loss of data
lda_gibbs_cython.c(4811) : warning C4101: 'getbuffer_cobj' : unreferenced local
variable
lda_gibbs_cython.c(4842) : warning C4101: 'releasebuffer_cobj' : unreferenced lo
cal variable
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\Bin\amd64\link.exe /DLL /n
ologo /INCREMENTAL:NO /LIBPATH:C:/GSL/lib /LIBPATH:C:\Python27\libs /LIBPATH:C:\
Python27\PCbuild\amd64 gsl.lib gslcblas.lib /EXPORT:initlda_gibbs_cython build\t
emp.win-amd64-2.7\Release\lda_gibbs_cython.obj /OUT:D:\LDA\pythonLDA\lda_
gibbs_cython.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\lda_gibbs_cython.lib /
MANIFESTFILE:build\temp.win-amd64-2.7\Release\lda_gibbs_cython.pyd.manifest /MAN
IFEST
LINK : fatal error LNK1181: cannot open input file 'gsl.lib'
error: command 'link.exe' failed with exit status 1181

GCC尝试

我安装了TDM-GCC,因此可以使用标准的cmd窗口:

I installed TDM-GCC so i could use the standard cmd window:

.pyx和setup.py保持不变.我在这里记录并解决了一个问题

.pyx, and setup.py remain the same.I had an issue documented and resolved here -mno-cygwin : gcc building Mercurial (Windows 2000) . Still no cigar. I dont know if this should be a separate question - will move if the experts think so.

D:\LDA\pythonLDA>setup.py build_ext --inplace -c mingw32
running build_ext
skipping 'lda_gibbs_cython.c' Cython extension (up-to-date)
building 'lda_gibbs_cython' extension
C:\MinGW64\bin\gcc.exe -mdll -O -Wall -IC:\Python27\lib\site-packages -IC:/GSL/i
nclude -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include
-IC:\Python27\PC -c lda_gibbs_cython.c -o build\temp.win-amd64-2.7\Release\lda_g
ibbs_cython.o
writing build\temp.win-amd64-2.7\Release\lda_gibbs_cython.def
C:\MinGW64\bin\gcc.exe -shared -s build\temp.win-amd64-2.7\Release\lda_gibbs_cyt
hon.o build\temp.win-amd64-2.7\Release\lda_gibbs_cython.def -LC:/GSL/lib -LC:\Py
thon27\libs -LC:\Python27\PCbuild\amd64 -lgsl -lgslcblas -lpython27 -l -o D:\LDA\pythonLDA\lda_gibbs_cython.pyd
gcc: error: D:\LDA\pythonLDA\lda_gibbs_cython.pyd: No such file or direct
ory
error: command 'gcc' failed with exit status 1

推荐答案

我只使用了 CythonGSL -当前版本(博客帖子,其中有详细说明.

I only used CythonGSL - the current version (https://github.com/twiecki/CythonGSL/blob/master/cython_gsl/__init__.py) reads environmental variable LIB_GSL to determine the location of GSL directory. Make sure you have LIB_GSL environmental variable to point your main GSL folder (not \bin folder). For example, LIB_GSL=C:/GSL. And then you have to add C:\GSL\bin to your PATH. I have a blog post with detailed explanation.

聊天讨论中的更多说明: TDM-GCC + EPD + GSL (有微小的变化-GSL文件必须位于 C:\ Program Files \ GnuWin32 \ .这对于64位Windows 7十分适用.

More explanations from Chat Discussion: TDM-GCC + EPD + GSL (with a minor change - GSL files have to be at C:\Program Files\GnuWin32\. This works perfectly for 64 bit windows 7.

使用可能是在MS VS C ++ 2008上编译的Windows二进制文件可能导致与 mingw64 编译的C ++程序冲突.

Using the Windows binaries which were probably compiled on MS VS C++ 2008 could lead to conflict with mingw64 compiled C++ programs.

有关设置的更多说明(已添加)

通常,使用科学的python发行版(例如 Python(x,y))要容易得多(免费),思想冠层(EPD的前身,有限的免费版本),或 Anaconda (高级软件包除外,免费),而不是在香草python之上安装单个软件包.似乎所有三个发行版都随MinGW一起提供,因此如果不需要对Cython的openmp支持,则应该很好,如果需要,则可以安装

In general, it is much easier to use a scientific python distribution such as Python(x,y) (Free), Enthought Canopy (successor of EPD, limited Free version), or Anaconda (Free except advanced packages) than to install individual packages on top of vanilla python. It seems all three distributions come with MinGW, so you should be good to if you don't need openmp support for Cython, and if you do, you can install TDM-GCC.

关于 GSL ,您可以从GSL "rel =" nofollow> oscats 项目.它具有带头标的32位和64位二进制文​​件.

In terms of GSL, you can download binary GSL from oscats projects. It has both 32 and 64 bit binaries with devel headers.

我的设置是 Anaconda + TDM-GCC + GSL (来自

My setup is Anaconda + TDM-GCC + GSL (from oscats projects) and it has been working very well.

这篇关于CythonGSL/在Windows上通过Cython使用GSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆