机器配置: 我的配置是 windows 7 x64,安装了 python 2.7 和 cython 0.18(全 64 位)。我还安装了 MS C++ 2008 Visual Studio。
我有 GSL 二进制文件,并且 Path 指向 GSL\Bin。
我正在使用 MS VS 2008 + SDK 7.0 来编译 cython .pyx 文件。我使用 SDK 7.0 命令提示符编译为 c 和 cython。
问题 但是在编译时我收到 LINK 错误 2019,这表明 GSL 文件夹中的头文件未找到。
我的尝试 为了解决这个问题,我下载了 CythonGSL。使用“来自 cythonGSL cimport *”没有用。我去了这个包的初始化文件并更改了它似乎正在搜索的目录以适合我安装 GSL 的位置。如 CythonGSL 自述文件所示,我已更新 setup.py。
这也不起作用!在编译时,它说 gsl.lib 未找到。
知道如何解决这个问题吗?
一种选择是,如果我可以指向一个静态地址,例如,代替
cdef extern from "libcalg/queue.h":
with
cdef extern from "FUll File Path/queue.h":
这暂时行不通。
安装程序.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()
我的 .pyx 文件:(从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 尝试的错误消息:
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
海合会尝试
我安装了 TDM-GCC,所以我可以使用标准的 cmd 窗口:
.pyx 和 setup.py 保持不变。我在此处记录并解决了一个问题-mno-cygwin:gcc building Mercurial (Windows 2000)。还是没有雪茄。我不知道这是否应该是一个单独的问题——如果专家这么认为,我会采取行动。
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