在Windows上安装CLD库文件并绑定到Python [英] Installing CLD libary on windows and bind to Python

查看:258
本文介绍了在Windows上安装CLD库文件并绑定到Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Python脚本中使用Chromium的Compact Language Detector库。

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

AFAIK,有两个项目可以利用这个库,但我有一直在将他们中的任何一个设置在Windows 7机器上遇到麻烦。

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.

我遇到了一些类似的问题, Mike McCandless原创项目 GoogleCode ),但我发现马特桑福德分享同一个项目 github )。对于这个问题,我将关注Matts项目,因为它似乎更经常更新(但很高兴能得到适用于任一项目的答案)。

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).


  • 以压缩格式下载项目,并提取到我的本地驱动器。

  • 从CMD运行vcvarsall.bat

  • 然后运行build.win.cmd批处理文件。 正常运行

  • 将生成的libcld.lib复制到ports / python /cld.lib

  • 尝试运行

  • 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 ()关键字必须是字符串

exceptions.TypeError: init() keywords must be strings

++编辑++
找到
问题

++EDIT++ Found this issue:


setup.py在Windows上失败。解决这个问题的方法是让
pkgconfig返回字典{'define_macros':[('WIN32',None)],
'libraries':packages}

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?

推荐答案

试试这个补丁(适用于我):

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',

这篇关于在Windows上安装CLD库文件并绑定到Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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