Installing CLD libary on windows and bind to Python

主宰稳场 提交于 2019-12-12 04:45:26

问题


I have a need to make use of Chromium's Compact Language Detector library within a Python script.

AFAIK, there are two projects that leverage this library, but I have been having troubles with getting either of them set up on a Windows 7 machine.

I had some similar problems with Mike McCandless Original Project (GoogleCode), but I then spotted Matt Sanford fork on the same Project (github). For the purpose of this question, I will focus on Matts project, as it seems to have been updated more often (but happy to get an answer that works for either project).

  • Downloaded the project as a zip, and extracted to my local drive.
  • Ran vcvarsall.bat from CMD
  • Then ran the build.win.cmd batch file. This ran ok.
  • Copied the resulting libcld.lib to ports/python/cld.lib
  • Tried running the setup.py but it returns with the following against line 12.

    exceptions.TypeError: init() keywords must be strings

++EDIT++ Found this issue:

setup.py fails on Windows. The hackish solution to fix this is to make pkgconfig return the dict {'define_macros': [('WIN32',None)], 'libraries': packages}

Im a bit of a rookie, but not entirely sure on the steps to implement this hack. Can anyone give me some slightly more verbose steps?


回答1:


Try this patch (works for me):

diff --git a/ports/python/setup.py b/ports/python/setup.py
index e1950c3..889f21a 100644
--- a/ports/python/setup.py
+++ b/ports/python/setup.py
@@ -9,7 +9,10 @@ def pkgconfig(*packages, **kw):

 module = Extension('cld',
                    ['pycldmodule.cc'],
-                   **pkgconfig('cld'))
+                   define_macros=[('WIN32', None)],
+                   libraries=['libcld'], 
+                   include_dirs=['..\\..\\'],
+                   library_dirs=['..\\..\\'])

 setup(name='cld',
       version='0.031415',


来源:https://stackoverflow.com/questions/13328180/installing-cld-libary-on-windows-and-bind-to-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!